views:

100

answers:

1

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

Edit

I want to make it possible to: 1) include a complete request (like controller/action) inside an other request 2) make a direct call to the controller/action as above

It is not only used for widgets, but I also want to build a page which contains content of other pages...

Edit 2

To be a bit more clear: I do have a page object that contains several elements. These elements can be simple elements (text, image, etc) and special elements, which are controller:action calls. Each page can contain "unlimited" (special) elements. I simply want to loop through these elements, define which kind of element I'm dealing with and add the result of that Element to the content 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;
    }
}
+1  A: 

It all depends, what are you trying to do.

Probably the action stack or action view helpers will do the work for you, but this may be not the best solution, because the dispatch overhead (probably will be removed in ZF2).

The second approach are view helpers with call to the models and actions in the controllers directly. You may use action helpers (and a static call to them) to access controller logic.

Also, see this blog post:

Using Action Helpers To Implement Re-Usable Widgets - phly, boy, phly

takeshin
I'm affraid this is not sufficient. Look at the modification at my original post
Stegeman
@Stegeman: I haven't looked at Kohana implementation, but in ZF Action stack is what you want. However is should be avoided (already discussed why) and the solution I posted is a recommended replacement for action stack.
takeshin
I gave it a try, but didn't manage to get it to work. Started an other threat about it: http://stackoverflow.com/questions/3979234/zend-framework-widget-tutorial-question
Stegeman
@Takeshin: If I do understand correctly, I can't decide on page level which "widget" I want to display?
Stegeman
@Stageman You need to examine the request to determine the module/controller/action or url and add a condition based on it, whether to display or not the widget (this is usually practiced in controller plugins too).
takeshin