Code Igniter follows the MVC patter by default. But it is always a bonus when we can work on HMVC. This approach really helps in applications with a lot of modular function and also these modules can become reusable. For example, once a user module is created with all the "Authentication", "User creation", "Forgot password" and other general functions which are required by almost all applications, such modules really help.
To use the HMVC architecture in Code Igniter, we use a plug-in which you can download from this link: https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc/wiki/Home. This package comes with two folders; and we need to add the files in the following folders in Code Igniter. First I have added the files inside the core folder and here is the screenshot for the same:
Core folder files
Once this is done, we need to add the content of the folder "third party". Here I have added the full MX folder which has 8 files inside.
The MX folder
And here is the screenshot of the MX folder inside the third party. This is very important that you follow these steps exactly the same way for the HMVC structure to work correctly.
The MX folder content
Once this is done, we can add modules inside a folder called modules inside the application module. Here is the screen shot of the modules folder inside the application folder of Code Igniter folder.
The modules folder
This is the folder where we can create our own reusable modules. Like I mentioned in the start, here is the structure for the user module that I have created. The modules folder should follow the structure where your controller is inside the "controllers" folder; the model is inside the "models" folder and the views are inside the "views" folder.
The modules folder structure