Zend 框架中的 HMVC [英] HMVC in Zend Framework

查看:24
本文介绍了Zend 框架中的 HMVC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在 Zend Framework 中使用 HMVC 模式?它默认在 Kohana 3 中实现,我真的很喜欢它,所以现在我想在 Zend Framework 中使用它.

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.

编辑

我想让:1) 在另一个请求中包含一个完整的请求(如控制器/动作)2) 直接调用上面的控制器/动作

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...

编辑 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.

喜欢:

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;
    }
}

推荐答案

这完全取决于你想做什么.

It all depends, what are you trying to do.

可能动作堆栈或动作视图助手会为您完成这项工作,但这可能不是最佳解决方案,因为调度开销(可能会在 ZF2 中移除).

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:

使用操作助手实现可重复使用的小部件 - phly、boy、phly

这篇关于Zend 框架中的 HMVC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆