Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing values to the Layout in Zend Framework.....?

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

like image 700
Pushpendra Avatar asked Feb 14 '11 08:02

Pushpendra


2 Answers

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
like image 76
Gordon Avatar answered Oct 16 '22 03:10

Gordon


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
like image 21
JF Dion Avatar answered Oct 16 '22 04:10

JF Dion