如何在Zend Framework 2中设置其他模块的模板?我有两个模块:
- 模块" A" (这是我的主题)
- 模块" B" (这是一种插件/小部件)
我想在模块" A"设置模块模板" B"。
我试过了:
public function viewAction()
{
// This is action of controller from module A
$view = new ViewModel();
$widget = new ViewModel(array('article' => $article));
$widget->setTemplate('B/content/article'); // <-- Doens't work
$view->addChild($articleView, 'article');
return $view;
}
但是这个例子并不起作用。那么如何将其他模块的标识符传递给setTemplate()函数呢?或者可能有其他功能/方式设置它? 谢谢你的帮助
答案 0 :(得分:0)
也许你需要将布局重新映射到你想要的东西,在你的模块配置上尝试这样的东西:
'view_manager' => array(
'template_path_stack' => array(
'MODULE_A' => __DIR__ . '/../view',
),
'template_map' => array(
'B/content/article' => __DIR__ . '/../../MODULE_B/view/article/article.phtml',
),
),
答案 1 :(得分:0)
我遇到了类似的问题 - 创建了我自己的模块,想要从这个模块渲染模板,而无需修改主模块的配置。
似乎本教程将回答您的问题:
http://framework.zend.com/manual/current/en/modules/zend.view.renderer.php-renderer.html
示例代码:
$oRenderer = new \Zend\View\Renderer\PhpRenderer();
$oResolver = new \Zend\View\Resolver\AggregateResolver();
$oRenderer->setResolver($oResolver);
$oResolverMap = new \Zend\View\Resolver\TemplateMapResolver(array(
'yourtemplate' => __DIR__ . '/view/yourtemplate.phtml',
));
$oResolverPath = new \Zend\View\Resolver\TemplatePathStack(array(
'script_paths' => array(
__DIR__ . '/view',
),
));
$oResolver->attach($oResolverMap);
$oResolver->attach($oResolverPath);
$oResolver->attach(new \Zend\View\Resolver\RelativeFallbackResolver($oResolverMap));
$oResolver->attach(new \Zend\View\Resolver\RelativeFallbackResolver($oResolverPath));
$oView = new \Zend\View\Model\ViewModel();
$oView->setTemplate('yourtemplate');
$sRenderedTemplateSource = $oRenderer->render($oView);