Why HMVC instead of MVC for Codeigniter? Why HMVC instead of MVC for Codeigniter? codeigniter codeigniter

Why HMVC instead of MVC for Codeigniter?


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

This is most useful when you need to load a view and its data within a view. Think about adding a shopping cart to a page. The shopping cart needs its own controller which may call a model to get cart data. Then the controller needs to load the data into a view. So instead of the main controller handling the page and the shopping cart, the shopping cart MVC can be loaded directly in the page.

The main controller doesn’t need to know about it, and is totally isolated from it.In CI we can’t call more than 1 controller per request. Therefore, to achieve HMVC, we have to simulate controllers. It can be done with libraries, or with this “Modular Extensions HMVC” contribution.

The differences between using a library and a “Modular HMVC” HMVC class is:

  1. No need to get and use the CI instance within an HMVC class
  2. HMVC classes are stored in a modules directory as opposed to the libraries directory.


I think native CI is not HMVC, it's just MVC. There's only 'controller', 'model', and 'view' inside of it, no 'module'.

So don't worry about why CI is HMVC if you don't need the benefit from HMVC.

By the way, if you really need HMVC pattern and the benefit from modularization, you can use the extentions:

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

https://github.com/jenssegers/codeigniter-hmvc-modules