HMVC stands for Hierarchical Model View Controller(HMVC). Why developers use HMVC instead of MVC is of handling n-tier Web architecture or multi -tier. Here, the software is engineered to have the processing, data management, and presentation functions physically and logically separated.
The HMVC pattern decomposes the client tier into a hierarchy of parent-child MVC layers. This is shown in the image.
The benefits of usnig HMVC is:
- More efficient development : friendly for development. This way,the presentation professionals work on the presentation tier and the database experts work on the data tier.
- Easy to add new features. If you want to introduce a new feature, you can add it to the appropriate tier without affecting the other tiers.
- Easy to reuse. Because of independent tiers, you can easily reuse each tier for other software projects.
- Modularization: Reduction of dependencies between the disparate parts of the application.
- Organization: Having a folder for each of the relevant triads makes for a lighter work load.
- Reusability: By nature of the design it is easy to reuse nearly every piece of code.
- Extendibility: Makes the application more extensible without sacrificing ease of maintenance.
These advantages will allow you to get M.O.R.E out of your application.
Setting HMVC in Codeigniter
Please follow below steps to setup an HMVC Codeigniter application.
Step 1 : Download Codeigniter application
You can download php codeigniter framework from, https://www.codeigniter.com/download .
After downloading the file, unzip it and move to your server.
Create a new folder in your application directory and name its as ‘modules’. Different modules are created in modules directory with controller, model and view directory.
Step 2 : Download HMVC Extension
HMVC extension can download from https://bitbucket.org/SoorajP/
After downloading unzip the file.
Step 3 : Installation
Merge the core and third_party folders to your codeigniter application.
Open core folder in your codeigniter application and create a new php file called CI_Controller.php. After that Copy and paste below code to this file.
Step 4 : Create modules
Next step is to create modules.
- Create new directory in your application folder and named it as ‘modules’.
- Need to create module specific controller,view and module folders in each module of your project.
Remaining process are similar to codeigniter MVC application. (that is auto load,database configuration).