I'm use zend framework 1.
我需要将 phtml 文件包含在另一个文件中并将参数发送到第一个文件。
前任:
我有索引控制器.php
我已经在控制器内部定义了$numberOfItem
我需要在 index.phtml 中渲染(包含)menu.phtml 并将$numberOfItem
变量发送给它
谢谢
你可以使用 zend partial 来做到这一点
在你的索引.phtml 做
echo $this->partial('yourfolder/menu.phtml', array('numberOfItem' => $numberOfItem));
在您的 menu.phtml 中,您可以使用
$this->numberOfItem
它的Zend部分。
在索引控制器中,您将像往常一样将 numberOfItem 值传递给相应的视图。
$this->view->numberOfItem = $numberOfItem;
然后,在 index.phtml 中:
echo $this->partial('viewfolder/menu.phtml', array('numberOfItem' => $this->numberOfItem));
在 menu.phtml 中:
echo $this->numberOfItem;
部分路径中的视图文件夹将与"视图/脚本"中的相对文件夹相同。例如,即使 index.phtml 和 menu.phtml 都在同一个文件夹 "application/views/scripts/index" 中,您也需要将路径传递给 partial 作为 index/menu.phtml