Zend Framework 中如何从视图调用视图?
我需要从视图内部渲染视图。
为了方便起见,我将它们称为块。
我有 5 个控制器,每个控制器都有一个名为 BlockAction() 的操作,并且它显示来自该控制器的一些信息。
在整个网站的索引页面中,我需要调用所有 5 个 BlockAction 视图。做到这一点的最佳方法是什么?
谢谢!
I need to render a view from inside a view.
For the sake of question, i'll call them blocks.
I have 5 controllers, each of them has an action that is called BlockAction(), and it displays some of the information from that controller.
In the Index page for the whole website I need to call all 5 of those BlockAction views. What could be the best way to do this?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可能想查看
Zend_Layout
,我相信您会发现它是一个更抽象的解决方案,并且可以让您更好地控制视图。基本上,“布局”是其中有多个视图的视图(我知道是多余的)。You might want to take a look into
Zend_Layout
, I believe you will find it to be a more abstract solution and give you more control over the views. Basically the "layout" is the view which has multiple views within it (Redundant I know).只是添加到已经给出的答案中。
虽然为块提供单独的控制器和操作的方法最符合经典的 MVC 方法,其中 UI 的每个部分都有其相应的控制器,但不建议将其与 Zend Framework 一起使用。
理论上你可以使用 ActionStack Action Helper 或 操作视图助手来调用控制器操作。然而,这将使您的应用程序经历每次调用的完整调度周期。
进一步阅读:
Just adding to the already given answers.
While the approach to have separate controllers and action for blocks is most true to the classic MVC approach, where each part of the UI has it's corresponding controller, it is not advisable to use it with Zend Framework.
In theory you could use the ActionStack Action Helper or Action View helper to call the controller actions. However this would make your application go through the full dispatch cycle for each call.
Further reading: