HMVC in Zend Framework

Can I use the HMVC pattern in the Zend Framework? It is implemented in Kohana 3 by default, and I really like it, so now I want to use it in the Zend Framework.

Edit

I want to make it possible: 1) to include a full request (for example, a controller / action) inside another request 2) to make a direct call to the controller / action, as described above

It is used not only for widgets, but also I want to create a page containing the contents of other pages ...

Edit 2

To be more clear: I have a page object that contains several elements. These elements can be simple elements (text, image, etc.) and special elements that are controllers: action calls. Each page may contain "unlimited" (special) elements. I just want to skip these elements, determine which element I am referring to, and add the result of this element to the contents of my view.

Like:

foreach($Page->Elements AS $Element) { switch(get_class($Element)) { case "Base\TextElement": // Add text element to content ... break; case "Base\SpecialElement": // Get result of the controller:action call break; case "Base\ImageElement": // Add image element to content ... break; default: echo "No case defined for ".get_class($Element); die; } } 
+4
source share
2 answers

It all depends on what you are trying to do.

Probably the helpers of the action stack or the helpers of the action see the work for you, but this may not be the best solution, since the manager’s overhead (will probably be deleted in ZF2).

The second approach is help helpers with calling models and actions in controllers directly. You can use action helpers (and a static call for them) to access the controller logic.

Also see this blog post:

Using action assistants to implement reusable widgets - phly, boy, phly

+3
source

Since the Kohana HMVC model ultimately gives you a way to handle HTTP requests internally, you can create a Zend_Http_Client adapter that does the same. I wrote some proof of concept code to do this once; see zend-http-client-adapter-internal .

An example of calling HelloController from IndexController :

 class IndexController extends Zend_Controller_Action { public function indexAction() { $client = new Zend_Http_Client("http://api.local/hello/?name=Clem"); $client->setAdapter(new Http_Client_Adapter_Internal( $this->getFrontController() )); $response = $client->request(); echo $response->getBody(); } } 

As you can see, instead of Kohana Request::factory($url) you need to construct a client ( api.local name is not used as a host name, I think, but some statement needs to be done), and then install its adapter. Obviously, these two steps are performed using the wrapper function.

0
source

All Articles