In this tutorial I will demonstrate the Hierarchical Model View Controller(HMVC) pattern, and how it applies to web application development. For this tutorial, I will use examples provided by CodeIgniter rapid php framework, and explain how HMVC can be a valuable modification to your development process.
This Introduction assumes you have an understanding of the Model View Controller (MVC) Pattern. We suggest you read this article [ Introduction to MVC ] to get acquainted with the topic before tackling this tutorial.
What is HMVC?
HMVC is an evolution of the MVC pattern used for most web applications today. It came about as an answer to the salability problems apparent within applications which used MVC.
The solution presented in the JavaWorld web site, July 2000, proposed that the standard Model, View, and Controller triad become layered into a “hierarchy of parent-child MCV layers“. The image below illustrates how this works.
Each triad functions independently from one another. A triad can request access to another triad via their controllers. Both of these points allow the application to be distributed over multiple locations, if needed. In addition, the layering of MVC triads allows for a more in depth and robust application development. This leads to several advantages which brings us to our next point.
Why should I use HMVC?
Key advantages to implementing the HMVC pattern in your development cycle:
- 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 with less headaches.
Setting up Code igniter:-
- Download code Igniter from here
- Extract the content of the Zip file to your web server’s document root.
- Rename the codeigniter zip to hmvc_ci
- open “hmvc_ci/application/config/config.php”
- locate $config[‘url’] var
- change it to your needs… for me it’s “localhost/hmvc_ci”
Open your browser and check “http://localhost/hmvc_ci”.