2012-10-03 159 views
1

我想添加其他模块的观点在我的布局ZF2的addChild视图模型,所以我这样做:另一个模块

$layoutTestdrive = new ViewModel(); 
$layoutTestdrive->setTemplate('testdrive6'); 
$view = new ViewModel(); 
$view->addChild($layoutTestdrive); 
return $view; 

在我module.config.php我这样做:

'Zend\View\Resolver\TemplateMapResolver' => array(
'parameters' => array(
'map' => array(
    'testdrive6' => __DIR__ . '/../../Testdrive/view/layout/testdrive6.phtml' 
     ), 
    ), 
), 

这是正确的吗?

+0

只要记住,我有两个模块,第一个模块必须从另一个模块(本例中为Testdrive)渲染布局。 – Jorgeley

回答

0

嗨,我认为你需要使用前进第一

public function commentAction(){  

    $list = $this->forward()->dispatch('comment_controrller', array('action' => 'list')); 
    $add = $this->forward()->dispatch('comment_controrller', array('action' => 'add')); 

    $view = new ViewModel(); 
    $view->addChild($list, 'list'); 
    $view->addChild($add, 'add'); 
    return $view; 
} 

我希望这将有助于

,或者如果你只想改变模板看到Different layout file for different controller