問題描述
我有幾個(gè)視圖部分(如分頁器部分),我希望它們可用我的應(yīng)用程序中的所有視圖腳本.
是否有一個(gè)目錄可以讓我放入部分競(jìng)爭(zhēng),并且所有人都可以使用它們?
或者,我如何定義這樣的目錄?
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?
推薦答案
您可以在視圖文件夾中創(chuàng)建一個(gè)具有任何名稱的文件夾,您可以從您的視圖中使用以下代碼調(diào)用部分,并作為第二個(gè)參數(shù)傳遞一個(gè)數(shù)組將在部分中使用的值.
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));
請(qǐng)注意,您可以從以視圖文件夾為根目錄的任何視圖中包含和渲染任何部分視圖.并且您將使用 $this 標(biāo)識(shí)符訪問部分中的變量以引用每個(gè)變量,就好像它是部分對(duì)象的成員一樣:
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;
或者,您也可以創(chuàng)建視圖助手 - 視圖助手是從 Zend_View_helper 類聲明和擴(kuò)展的類,可以從視圖中調(diào)用,就像它是成員函數(shù)一樣.
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.
有關(guān)視圖助手的更多信息,您可以參考 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
這篇關(guān)于我在哪里保存 Zend Framework 中的部分(視圖),以便我的應(yīng)用程序中的所有視圖都可以訪問?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!