我必须使用 zend 框架向一个相当大的应用程序添加一个功能。
我有一个观点。在那个 View 中,我有一个 if 并且想在同一位置包含另一个 .phtml。
所以,此刻我得到了类似的东西
if (x = true)
require_once(the other file);
那行得通,但不是 zend 的意思。有人告诉我应该使用 View 助手,更具体地说,是部分 View 助手。那么,如何在部分文件中包含一个 phtml 文件?我不明白。
最佳答案
像这样使用 render()
View 助手:
<?=$this->render('the other.phtml')?>
当前 .phtml 脚本中可用的所有 View 变量也将在 other.phtml
中可用。
如果你想渲染带有特定 View 变量的其他 View 脚本,请改用partial
:
<?=$this->partial('the other.phtml', array(
'var'=>'value',
'var2'=>'value2',
...
))?>
关于php - 包含 .phtml zend,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4818347/