我在哪里保存 Zend Framework 中的部分(视图),以便我的应用程序中的所有视图都可以访问?
我有几个视图部分(如分页器部分),我希望它们可用我的应用程序中的所有视图脚本.
是否有一个目录可以让我放入部分竞争,并且所有人都可以使用它们?
或者,我如何定义这样的目录?
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?
推荐答案
您可以在视图文件夹中创建一个具有任何名称的文件夹,您可以从您的视图中使用以下代码调用部分,并作为第二个参数传递一个数组将在部分中使用的值.
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));
请注意,您可以从以视图文件夹为根目录的任何视图中包含和渲染任何部分视图.并且您将使用 $this 标识符访问部分中的变量以引用每个变量,就好像它是部分对象的成员一样:
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;
或者,您也可以创建视图助手 - 视图助手是从 Zend_View_helper 类声明和扩展的类,可以从视图中调用,就像它是成员函数一样.
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.
有关视图助手的更多信息,您可以参考 Zend 上的这篇文章 http://devzone.zend.com/article/3412-View-Helpers-in-Zend-Framework
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
相关文章