3

I searched HMVC and know what it is and its advantages.

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.

But just in Codeigniter without HMVC, different sub-folders for controller and multiple model folders and multiple view folders can be created. I do not comprehend the exact reasons for using HMVC.

tereško
  • 58,060
  • 25
  • 98
  • 150
kalaba2003
  • 1,231
  • 3
  • 20
  • 33
  • 1
    HMVC is a bit more than just folders. in HMVC for example, a codeigniter controller can call **another** codeigniter controller, what cannot really be done in the native CI – Patrick Jun 15 '14 at 10:11
  • you can always make an API to do such stuff ? @Patrick – Maaz Rehman Mar 03 '17 at 14:01
  • If you would, you'd recreate the hmvc extension, as the loader class woukd have to be extended, much like in hmvc – Patrick Mar 03 '17 at 16:42

2 Answers2

3

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.
kalaba2003
  • 1,231
  • 3
  • 20
  • 33
1

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

尤川豪
  • 459
  • 5
  • 26