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:-

Requirement :-

  1. Download code Igniter from here
  2. Extract the content of the Zip file to your web server’s document root.
  3. Rename the codeigniter zip to hmvc_ci
  4. open “hmvc_ci/application/config/config.php”
  5. locate $config[‘url’] var
  6. change it to your needs… for me it’s “localhost/hmvc_ci”
Screenshot for HMVC
Test that we have a working version of code igniter.
Open your browser and check “http://localhost/hmvc_ci”.
You should be greeted with the “Welcome to Code igniter” screen.
Then Download and Install HMVC extension.
Download version 5.2 of the modular extension from here .
Move Core folder files to code igniter core folder and third party MX folder to third party code igniter folder.
Recheck your browser…You should still see the Welcome to code igniter screen.
It’s time to add the modules:-
Create the following directory structure. “application/modules/welcome/controllers/”.
Move the “application/view/welcome_message.php” to “application/modules/welcome/view/welcome_message.php”
Do a final check to your browser. You should still see the Welcome to Code igniter screen. That’s it! Modular extensions is installed correctly.
For now we demonstrate what is HMVC design pattern and why should we use it and how to install HMVC on code igniter php framework
In next chapter I will show you some examples in real life HMVC
keep in touch 🙂