我想将整个错误处理捆绑在一个模块中。到目前为止,它还在工作,但是错误模板仍然是默认的[project root]/module/Application/view/error/index.phtml。我想使用它,但是用我的附加代码包装。为此,我需要将默认异常模板添加为分部。不可能(不再)将模块名称传递给部分视图助手。因此,我尝试了这个(建议使用here):
[project root]/module/ErrorHandling/view/exception.phtml
echo $this->partial('Application/error/index');但没有用:
Zend\View\Exception\RuntimeException: Zend\View\Renderer\PhpRenderer::呈现:无法呈现模板“应用程序/错误/索引”;解析器无法解析为/var/www/.../my-project/vendor/zendframework/zend-view/src/Renderer/PhpRenderer.php:494中的文件
它只适用于来自/module/{AnotherModule}/view/{another-module}子文件夹的视图。
如何从另一个模块(但在/module/{AnotherModule}/view/{another-module} 子文件夹之外)获取呈现为分部的视图?
发布于 2016-05-19 15:25:41
解决方法是将所需的视图添加到view的模板映射中,例如:
config/autoload/global.php
return [
'view_manager' => [
'template_map' => [
'default_zf_error_view' => __DIR__ . '/../../module/Application/view/error/index.phtml'
]
]
];这是可行的,但它仍然是有趣的知道,如何解决这个问题的一个更干净的方式。
发布于 2016-05-19 16:42:13
您不必将它添加到global.php中
将其添加到模块的module.config.php中就足够了。这些视图也可以在其他模块中访问,因为ZF2合并了不同模块的所有配置文件。在这里阅读更多关于Advanced Configuration Tricks的内容。
所以在module.config.php中:
return [
//...
'view_manager' => [
'template_map' => [
'default_zf_error_view' => __DIR__ . '/../../module/Application/view/error/index.phtml'
]
]
//...
];在任何其他模块的控制器中,您现在可以这样做:
$viewModel->setTemplate('default_zf_error_view');https://stackoverflow.com/questions/37326552
复制相似问题