Passing values to the Layout in Zend Framework…?

我是研究僧i 提交于 2020-01-13 08:51:15

问题


I am facing a problem in zend-framework related to layout. Here I have to pass some values to the layout that will be used to display the top-ranking users of the site.

Since I am new to zend-framework, I'm not able to find any way to do so.

If you have any code, idea or link, please provide me.....

Thanks in advance...........


回答1:


Create a Controller Plugin that fetches this data anytime before the layout is rendered and pass the data to to the view. Then render that data on your layout.phtml like you would render any other data, e.g. use a ViewHelper or a Partial.

See http://zendframework.com/manual/en/zend.controller.plugins.html

Or use an Action Helper as explained at

  • http://weierophinney.net/matthew/archives/246-Using-Action-Helpers-To-Implement-Re-Usable-Widgets.html



回答2:


The layout in Zend Framework is just an other view. We could define the layout as the "outer view" and the view associated with a controller action as the "inner view". To send data to the layout from a controller you can simply like this

From the controller

$this->view->someData = $data

From the layout

$this->someData


来源:https://stackoverflow.com/questions/4990080/passing-values-to-the-layout-in-zend-framework

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!