【发布时间】:2013-10-19 10:03:35
【问题描述】:
我正在使用 zend 框架 1。
我需要在另一个文件中包含 phtml 文件并将参数发送到第一个文件。
例如:
我有 indexController.php
我在控制器内部定义了$numberOfItem
我需要在 index.phtml 内渲染(包含) menu.phtml 并向其发送$numberOfItem 变量
谢谢
【问题讨论】:
标签: php zend-framework
我正在使用 zend 框架 1。
我需要在另一个文件中包含 phtml 文件并将参数发送到第一个文件。
例如:
我有 indexController.php
我在控制器内部定义了$numberOfItem
我需要在 index.phtml 内渲染(包含) menu.phtml 并向其发送$numberOfItem 变量
谢谢
【问题讨论】:
标签: php zend-framework
你可以使用 zend partial 来做到这一点
在你的 index.phtml 中做
echo $this->partial('yourfolder/menu.phtml', array('numberOfItem' => $numberOfItem));
在您的 menu.phtml 中,您可以使用
读取打印变量$this->numberOfItem
【讨论】:
它的Zend partial。
在 IndexController 中,您将照常将 numberOfItem 值传递给相应的视图。
$this->view->numberOfItem = $numberOfItem;
然后,在 index.phtml 中:
echo $this->partial('viewfolder/menu.phtml', array('numberOfItem' => $this->numberOfItem));
在menu.phtml中:
echo $this->numberOfItem;
部分路径中的 viewfolder 将与“view/scripts”中的相对文件夹相同。例如,即使您的 index.phtml 和 menu.phtml 都在同一个文件夹“application/views/scripts/index”中,您也需要将路径传递给 partial 作为 index/menu.phtml
【讨论】: