我正在研究this tutorial。我已经按照所有步骤创建了目录结构、控制器、module.php和module.config.php,但当我打开http://zf2-tutorial/album时,我得到以下错误:
Fatal error: Uncaught exception 'Zend\View\Exception\RuntimeException' with message 'Zend\View\Renderer\PhpRenderer::render: Unable to render template "album/album/index"; resolver could not resolve to a file' in /var/www/zf2-tutorial/vendor/zendframework/zendframework/library/Zend/View/Renderer/PhpRenderer.php:461我在视图/相册/相册目录下的模块目录中创建了一个名为index.phtml的文件。
module.config.php:
return array(
'controllers' => array(
'invokables' => array(
'Album\Controller\Album' => 'Album\Controller\AlbumController',
),
'view_manager' => array(
'template_map' => array(
'layout/layout' => __DIR__ . '/../view/layout/layout.phtml',
'album/album/index' => __DIR__ . '/../view/album/album/index.phtml',
'error/404' => __DIR__ . '/../view/error/404.phtml',
'error/index' => __DIR__ . '/../view/error/index.phtml',
),
'template_path_stack' => array(
'album' => __DIR__ . '/../view',
)
)
),
'router' => array(
'routes' => array(
'album' => array(
'type' => 'segment',
'options' => array(
'route' => '/album[/:action][/:id]',
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[0-9]+',
),
'defaults' => array(
'controller' => 'Album\Controller\Album',
'action' => 'index',
),
),
),
),
),
);怎么了?
发布于 2012-12-07 00:40:24
PhpRenderer对象出现问题,因为它找不到视图phtml文件。
文件module/Album/view/album/album/index.phtml是否存在?如果不是,那么这很可能是原因。
发布于 2013-06-20 14:21:57
检查是否在module.config.php文件中为view_manager提供了正确的参数或嵌套
发布于 2013-09-17 22:22:18
我也面临着同样的问题。我已经更改了文档中存在的文件module.config.php的以下行,
'view_manager' => array(
'template_path_stack' => array(
'album' => __DIR__ . '/../view',
),
),至
'view_manager' => array(
'template_path_stack' => array(
'album' => __DIR__ . '/../src/view',
),
),只需在视图文件夹前面添加src文件夹名称即可。
这样,您需要在所有视图路径之前添加'src‘文件夹名称。
https://stackoverflow.com/questions/13746666
复制相似问题