Hierarchical Model-View-Controller (HMVC) in Codeignitor

What is HMVC?

HMVC stands for Hierarchical Model View Controller. Module Controllers can be used as normal Controllers or HMVC Controllers and they can be used as widgets to help you build view partials.

HMVC is an updation of the MVC pattern used for many web applications. It has 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 Problem with MVC

The Model-View-Controller (MVC) architectural pattern is a great start to making your websites and web applications more sophisticated. However, there are limitations. Most professional web developer that uses the CodeIgniter framework (strictly MVC), they have had extensive, first-hand experience with MVC. At first, they thought it was great. It was so intuitive and well organized. The libraries and helpers were excellent. However, as your sites grew and evolved into the behemoth, it became apparent that MVC was not cutting it. As the number of files being developed grew from tens to hundreds to thousands, the ability to make systematic changes became increasingly complex. HMVC Hierarchical Model-View-Controller (HMVC) Architectural Pattern is the solution to this problem.

The MVC architectural pattern relies on the “triad” of components depicted below:

HMVC still uses this triad, but instead of limiting the developer to put all controllers in the same ./controllers/ base path, all models are in the same ./models/ base path, and all views are in the same ./views/ base path, HMVC allows developers to define separate “modules” to put their own models, views, and controllers directories inside their own unique paths.

HMVC implementation in Codeignitor

HMVC in Codeignitor

https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc

Modular Extensions – HMVC : Codeignitor

Modular Extensions makes the CodeIgniter PHP framework modular. Modules are groups of independent components, typically model, controller and view, arranged in an application modules sub-directory that can be dropped into other CodeIgniter applications.
Module Controllers can be used as normal Controllers or HMVC Controllers and they can be used as widgets to help you build view partials.

Features

All controllers can contain an $autoload class variable, which holds an array of items to load prior to running the constructor. This can be used together with module/config/autoload.php, however using the $autoload variable only works for that specific controller.

Leave a Reply

Your email address will not be published. Required fields are marked *

*
*
Website