I have a main controller and I want to call child controllers from this controller with HMVC. I setted a rule that routes parameter to a specific action that calls children controllers with “Request::factory” for the main controller but it didn’t work because of infinity loop. is there any way to do it?
I must use HMVC because main controller sends some information to children controller so I need a controlling layer.
It will be kind of a plugin for crud applications for a CMS.
The main controller: http://pastebin.com/nt2fhMEy
An example of child controller: http://pastebin.com/WqaHZaxf
Route: http://pastebin.com/6JGFf2i2 (I didn’t configure caction and cid yet.)
Extra Note: It will be kind of a crud module for my CMS. The main controller will load main template and some configs. Also the main controller includes some ORM functions and children controller must be able to use parent::functionname. The children controllers are in cruds/ directory and the cms creates them automatically.
You have a few mistakes in your idea of the controllers and HMVC.
The best way to do so is to use object oriented controllers. By this I mean the “child controllers” need to extend the main controller.
Let the main controllers extend Controller_Template and the child controllers extend the main controller.
When you send requests to child controllers through routes you will not only have access to the parent properties, but your request will do the following:
From what I get from your question you will not need HMVC at all. Actually it’s a very bad pattern for passing data. Keep in mind that when you perform an internal request through HMVC this is actually a completely new request. It will go through the routes and this list again. You will not have access to all of the previous request properties.
Another tip: don’t put ORM functions in the main controller. Use the actual ORM models instead.