architecture_codeigniter

Starting with CodeIgniter – Tutorial 1

CodeIgniter is best framework of PHP which follow MVC pattern. Learning Codeigniter will help you to learn Laravel as well.

To install the Codeigniter we need Composer first. Composer is like NPM (Node Package manager) It’s dependency manager. If your project uses many 3rd party library, composer will track those libraries/dependencies into ‘composer.json’ file.

Once you install the composer, you are ready to install Codeigniter. Currently the latest version is 4.3.6 in July 2023.

Now, See the directory structure of Codeigniter. It’s easy to get the idea. The main directory is app directory. You need to focus on 3 files on initial stage and env file.

env file

You need to change env to .env to make it applicable. It is having some global constants which will work through out the application. For example CI_ENVIRONMENT = production will not display all errors on front end so you have to change it to development to see all error during development time.

app – Config – App.php – Set your site URL here

app – Config – Database.php – Set your database details here

app – Config – Routes.php – Set your routes here

Rest you can review here.

app/
    Config/         Stores the configuration files
    Controllers/    Controllers determine the program flow
    Database/       Stores the database migrations and seeds files
    Filters/        Stores filter classes that can run before and after controller
    Helpers/        Helpers store collections of standalone functions
    Language/       Multiple language support reads the language strings from here
    Libraries/      Useful classes that don't fit in another category
    Models/         Models work with the database to represent the business entities
    ThirdParty/     ThirdParty libraries that can be used in application
    Views/          Views make up the HTML that is displayed to the client

You know about MVC pattern. Right? Controllers are the layer in between model & view. Controller decide which model to load and where to send the data (view). Model & Controller don’t carry HTML tags. View has HTML tags with PHP tags.

Now What are the namespace?

Namespaces are group of some classes. To avoid the naming confusion we group some classes into one box and that box is called namespace. For example User may be the class for many modules. So same class name for different modules creates confusion so we move that class to one box that is called namespace.

You need to know about hooks & helpers at this level.

Hooks are like WordPress hooks. They run before or after running any Controllers.

Helpers are stand alone functions.

You can review this tutorial on YouTube.