2013-03-18 119 views
1

我不希望孩子在动作控制器添加到视图模型:ZF2视图在另一个视图渲染

// action controller 
public function indexAction() { 
    $result = new ViewModel(); 
    $result->setTemplate('application/view/another-action'); 

    $comments = new ViewModel(); 
    $comments->setTemplate('application/view/child-comments'); 
    $result->addChild($comments, 'child_comments'); 

    return $result; 
} 
... 
// View 
<div> 
<?php echo $this->child_comments ?> 
</div> 

我想包括视图另一种观点认为:

<div> 
    <?php 
    $view = new ViewModel(); 
    $view->setVariables($this->var); 
    $view->setTemplate('page_nav.phtml'); 
    // here I want to render view 
    ?> 
</div> 

是否有可能?

回答

0

这是Partial视图助手做什么(文档似乎是过时的,但无论如何,我会联系他们here):

<div> 
    <?php echo $this->partial('page_nav', array('var' => $this->var)) ?> 
<div> 

显然,你page_nav应该由你的视图解析器闻名。

1

我知道这是旧的,但你也可以简单地拨打$this->render('path/to/view-script')