Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kohana 3.0's HMVC structure in layman's terms?

So, I think i understand the cascading filesystem in it's basic terms, but I can't seem to wrap my head around the 'H'ierachy structure of the MVC. Could anyone tell me the advantages of using HMVC over MVC and it's basic intended functionality?

Thanks for your time!

like image 755
soren.qvist Avatar asked Jun 10 '10 17:06

soren.qvist


2 Answers

HMVC is better suited to Widgets. For example, a Calendar widget might have its own controller, models, and set of views, and you can simply call its controller to render a certain view from inside the main page to embed the widget.

The emphasis is on reusable GUI elements. See here for additional reading: http://www.javaworld.com/javaworld/jw-07-2000/jw-0721-hmvc.html.

Edit: Here's an actual PHP-centric link: http://techportal.inviqa.com/2010/02/22/scaling-web-applications-with-hmvc/. Seems to have nicer illustrations as well.

like image 120
Lotus Notes Avatar answered Nov 18 '22 13:11

Lotus Notes


You can make a request for a page (controller and action is found by the routes) internal. You can do this for example:

class Controller_Menu extends Controller
{
    public function action_index()
    {
        $this->request->response = view stuff ...
        $this->request->response->set('...', ...) // some vars
    }
}

and

class Controller_Home extends Controller
{
    public function action_index()
    {
        $this->request->response = ...; // some view stuff...
        $this->request->response->set('menu', 
            Request::factory('menu')->execute()->response // here happens the magic
        );
    }
}

Every page who haves a menu dont have to do all the logic to load the menu etc. (e.g. from models). You just make a request to the controller, execute it, and get the result. Very usefull when used correctly.

like image 5
VDVLeon Avatar answered Nov 18 '22 13:11

VDVLeon