【问题标题】:include .phtml zend包括 .phtml zend
【发布时间】:2011-06-16 15:26:18
【问题描述】:
我必须使用 zend 框架为一个相当大的应用程序添加一个功能。
我有一个看法。在这种情况下,我有一个 if 并希望在同一位置包含另一个 .phtml。
所以,现在我得到了类似的东西
if (x = true)
require_once(the other file);
有效,但不是 zend 的意思。我被告知我应该使用视图助手,更具体地说,部分。那么,如何在部分中包含 phtml 文件?我不明白。
【问题讨论】:
标签:
php
zend-framework
view
helper
【解决方案1】:
像这样使用render() 视图助手:
<?=$this->render('the other.phtml')?>
当前 .phtml 脚本中可用的所有视图变量也将在 the other.phtml 中可用。
如果您想用特定的视图变量渲染其他视图脚本,请改用partial:
<?=$this->partial('the other.phtml', array(
'var'=>'value',
'var2'=>'value2',
...
))?>
【讨论】:
-
查看here 获取文档。该数组是要在the other.phtml 中设置的视图变量。使用xxx/myscript.phtml 作为路径(包括xxx/)。