我正在使用zend framework 1。如何將zend phtml文件包含到其他phtml文件中
我需要將phtml文件包含在另一個文件中並將參數發送到第一個文件。
例:
我已經indexController.php
和我有$numberOfItem
控制器
我需要渲染(包括)menu.phtml內限定內部索引.phtml併發送$numberOfItem
變量對它
感謝
我正在使用zend framework 1。如何將zend phtml文件包含到其他phtml文件中
我需要將phtml文件包含在另一個文件中並將參數發送到第一個文件。
例:
我已經indexController.php
和我有$numberOfItem
控制器
我需要渲染(包括)menu.phtml內限定內部索引.phtml併發送$numberOfItem
變量對它
感謝
可以使用zend的部分做
在您index.phtml做
echo $this->partial('yourfolder/menu.phtml', array('numberOfItem' => $numberOfItem));
,並在您menu.phtml就可以讀取打印使用的變量爲
$this->numberOfItem
在IndexController中,您將像往常一樣將numberOfItem值傳遞給相應的視圖。
$this->view->numberOfItem = $numberOfItem;
然後,在index.phtml:
echo $this->partial('viewfolder/menu.phtml', array('numberOfItem' => $this->numberOfItem));
在menu.phtml
:
echo $this->numberOfItem;
的viewfolder在部分的路徑將是相同的作爲相對從「視圖/腳本」文件夾。例如,即使您的index.phtml和menu.phtml都位於同一個文件夾「application/views/scripts/index」中,您仍需要將路徑傳遞給partial,如index/menu.phtml