【问题标题】:'Zend\View\Renderer\PhpRenderer::render: Unable to render template "error";'Zend\View\Renderer\PhpRenderer::render: 无法渲染模板“错误”;
【发布时间】:2015-03-17 10:15:05
【问题描述】:

我正在尝试实施Zf2Tutotrial 提供的教程。但我得到无法呈现模板“错误”下面提到的错误。

这是我的代码。

<?php

return array(
 'controllers' => array(
     'invokables' => array(
         'Album\Controller\Album' => 'Album\Controller\AlbumController',
     ),
 ),

     // The following section is new and should be added to your file
 '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',
                 ),
             ),
         ),
     ),
 ),

'view_manager' => array(
     'template_path_stack' => array(
         'album' => __DIR__ . '/../view',
     ),
 ),

【问题讨论】:

    标签: zend-framework2


    【解决方案1】:

    这可能是由于您的应用程序遇到某种ExceptionError 但由于找不到这些模板而无法呈现错误。

    要解决此问题,请尝试将此类错误的模板配置行添加到您的 view_manager 数组中:

    'view_manager' => array(
        'not_found_template' => 'error/404',
        'exception_template' => 'error/index',
        ...,
        'template_map' => array(
            'error/404' => __DIR__ . '/../view/album/error/404.phtml',
            'error/index' => __DIR__ . '/../view/album/error/index.phtml',
        ),
    ),
    

    当然还要确保这些模板使用 template_map 实际映射到现有模板。

    【讨论】:

    • 您好,威尔特,感谢您的回复。我根据您的建议更新了代码。我收到 无法呈现模板“错误/索引” 错误。我已将模板放在 module\Album\view\error 下。
    • 我在回答中添加了一些额外的信息。还要检查其他模块中的 view_manager 配置数组。您可能在应用程序的其他地方已经有模板配置(例如在您的 Application 模块中的 module.config.php 中。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-26
    • 1970-01-01
    • 1970-01-01
    • 2017-01-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多