Where do I save partial (views) in Zend Framework, to be accessible for all Views in my App?

一世执手 提交于 2019-12-18 02:37:36

问题


I have several view Partials (like paginator partial) which I want them to be available To all view scripts in my application.
Is there a directory I can put partial vies in, and they will be available to all?
Or, how do I define such a directory?


回答1:


You can create a folder in the views folder with any name and from your views you would call a partial using the following code and as the second argument pass an array of values which would be used within the partial.

$this->partial('your-partial-dir/your-partial.phtml', array('var'=>$myVar));

Note that you can include and render any partial view from any view referring to the views folder as the root. And you would access variables within the partial using the $this identifier to refer to each variable as though it was a member of the partial object:

//your-partial.phtml file

$this->var;

Alternatively you can also create a view helper - a view helper is a class that is declared and extended from the Zend_View_helper class and can be called from a view as though it was a member function.

For more on view helpers you can refer to this write up on Zend http://devzone.zend.com/article/3412-View-Helpers-in-Zend-Framework



来源:https://stackoverflow.com/questions/746260/where-do-i-save-partial-views-in-zend-framework-to-be-accessible-for-all-view

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