问题
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