【问题标题】:Unable to render template zf2无法渲染模板 zf2
【发布时间】:2012-10-22 06:13:50
【问题描述】:

我创建了名为“currency”的新模块并在 module.config 中配置了路由。它工作正常。 之后,我为货币汇率添加了名为 CrateController 的新控制器。还创建了表单、模型和视图文件。 但它没有正确路由。

错误:

致命错误:未捕获的异常 'Zend\View\Exception\RuntimeException' 带有消息 'Zend\View\Renderer\PhpRenderer::render: Unable to render template "currency/crate/index";解析器无法解析到文件....

任何检查这一点的线索都会有所帮助。

我的module.config文件如下。

return array(
'controllers' => array(
    'invokables' => array(
        'Currency\Controller\Currency' => 'Currency\Controller\CurrencyController',
        'Currency\Controller\Crate' => 'Currency\Controller\CrateController',
    ),
),

// The following section is new and should be added to your file
'router' => array(
    'routes' => array(
        'currency' => array(
            'type'    => 'segment',
            'options' => array(
                'route'    => '/currency[/:action][/:currency_id]',
                'constraints' => array(
                    'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
                    'currency_id'     => '[0-9]+',
                ),
                'defaults' => array(
                    'controller' => 'Currency\Controller\Currency',
                    'action'     => 'index',
                ),
            ),
        ),
       'crate' => array(
            'type'    => 'segment',
            'options' => array(
                'route'    => '/crate[/:action][/:c_rate_id]',
                'constraints' => array(
                    'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
                    'c_rate_id' => '[0-9]+',
                ),
                'defaults' => array(
                    'controller' => 'Currency\Controller\Crate',
                    'action'     => 'index',
                ),
            ),
        ),           
    ),
),

【问题讨论】:

    标签: php zend-framework2 zend-route


    【解决方案1】:

    检查两件事:

    第一:模板文件是否存在? ./module/Currency/view/currency/crate/index.phtml

    第二:检查./Currency/config/module.config.php内的以下条目

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

    【讨论】:

    • 糟糕..第一件事失败了。我没有在视图中的 crate 文件夹下创建 index.phtml 文件。第二件事没问题。现在它正在工作。谢谢山姆的帮助..
    猜你喜欢
    • 2016-02-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-30
    • 1970-01-01
    • 2021-03-04
    相关资源
    最近更新 更多