2011-01-27 62 views
4

我不得不使用zend框架添加一个功能到一个相当大的应用程序。包括.phtml zend

我有一个看法。在这个观点上,我有一个如果并且想要在同一位置包含一个其他的.phtml文件。

所以,此刻我得到的东西像

if (x = true) 
    require_once(the other file); 

的作品,但是,这不是在Zend中的意义。我被告知我应该使用视图助手,更具体的,部分。那么,我如何包含phtml文件的部分?我没有明白。

回答

12

使用render()视图助手这样的:

<?=$this->render('the other.phtml')?> 

在当前一个.phtml脚本可用的所有视图变量将在the other.phtml了。

如果你想渲染特定视图变量其他视图脚本,使用partial代替:

<?=$this->partial('the other.phtml', array(
    'var'=>'value', 
    'var2'=>'value2', 
    ... 
))?> 
+0

感谢。我会试试看。 – xotix 2011-01-27 15:47:20