我应该在Zend Framework中的哪里保存部分(视图),以便我的应用程序中的所有视图都可以访问? [英] Where do I save partial (views) in Zend Framework, to be accessible for all Views in my App?

查看:63
本文介绍了我应该在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?

推荐答案

您可以在views文件夹中创建任何名称的文件夹,并使用以下代码从视图中调用局部代码,并在第二个参数传递数组时使用在部分中使用的值.

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上的这篇文章

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

这篇关于我应该在Zend Framework中的哪里保存部分(视图),以便我的应用程序中的所有视图都可以访问?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆