ZF2如何为不存在的操作显示错误404

时间:2014-03-13 20:21:57

标签: php zend-framework2

我有一个基于Zend Framework 2的大型网站.URL遵循domain.tld / module / action / otherstuff的标准模式。

如果某人键入了不存在的模块,则会获得标准的404页面未找到消息。但是,如果用户转到有效模块但输入了无效的操作名称,则会收到消息

Zend\View\HelperPluginManager::get was unable to fetch or create an instance for escape

如何输出正常的404错误消息而不是此消息?我猜我在某处找不到正确的东西,但我不知道从哪里开始寻找。

这是堆栈跟踪:

C:\conversion\vendor\zendframework\zendframework\library\Zend\ServiceManager\ServiceManager.phpLine #495
#0 C:\conversion\vendor\zendframework\zendframework\library\Zend\ServiceManager\AbstractPluginManager.php(103): Zend\ServiceManager\ServiceManager->get('escape', true)
#1 C:\conversion\vendor\zendframework\zendframework\library\Zend\View\Renderer\PhpRenderer.php(378): Zend\ServiceManager\AbstractPluginManager->get('escape', NULL)
#2 C:\conversion\vendor\zendframework\zendframework\library\Zend\View\Renderer\PhpRenderer.php(397): Zend\View\Renderer\PhpRenderer->plugin('escape')
#3 C:\conversion\module\Supplier\view\error\404.phtml(56): Zend\View\Renderer\PhpRenderer->__call('escape', Array)
#4 C:\conversion\module\Supplier\view\error\404.phtml(56): Zend\View\Renderer\PhpRenderer->escape('Supplier\Contro...')
#5 C:\conversion\vendor\zendframework\zendframework\library\Zend\View\Renderer\PhpRenderer.php(507): include('C:\conversio...')
#6 C:\conversion\vendor\zendframework\zendframework\library\Zend\View\View.php(205): Zend\View\Renderer\PhpRenderer->render(Object(Zend\View\Model\ViewModel))
#7 C:\conversion\vendor\zendframework\zendframework\library\Zend\View\View.php(233): Zend\View\View->render(Object(Zend\View\Model\ViewModel))
#8 C:\conversion\vendor\zendframework\zendframework\library\Zend\View\View.php(198): Zend\View\View->renderChildren(Object(Zend\View\Model\ViewModel))
#9 C:\conversion\vendor\zendframework\zendframework\library\Zend\Mvc\View\Http\DefaultRenderingStrategy.php(102): Zend\View\View->render(Object(Zend\View\Model\ViewModel))
#10 [internal function]: Zend\Mvc\View\Http\DefaultRenderingStrategy->render(Object(Zend\Mvc\MvcEvent))
#11 C:\conversion\vendor\zendframework\zendframework\library\Zend\EventManager\EventManager.php(468): call_user_func(Array, Object(Zend\Mvc\MvcEvent))
#12 C:\conversion\vendor\zendframework\zendframework\library\Zend\EventManager\EventManager.php(207): Zend\EventManager\EventManager->triggerListeners('render', Object(Zend\Mvc\MvcEvent), Array)
#13 C:\conversion\vendor\zendframework\zendframework\library\Zend\Mvc\Application.php(347): Zend\EventManager\EventManager->trigger('render', Object(Zend\Mvc\MvcEvent))
#14 C:\conversion\vendor\zendframework\zendframework\library\Zend\Mvc\Application.php(322): Zend\Mvc\Application->completeRequest(Object(Zend\Mvc\MvcEvent))
#15 C:\conversion\public\index.php(25): Zend\Mvc\Application->run()
#16 {main}            

1 个答案:

答案 0 :(得分:1)

in module.config.php

'view_manager' => array(
        'display_not_found_reason' => true,
        'display_exceptions' => true,
        'doctype' => 'HTML5',
        'not_found_template' => 'error/404',
        'exception_template' => 'error/index',
        'template_map' => array(
            'application/index/changelocal' => __DIR__ . '/../view/application/index/changelocal.phtml',
            'application/index/index' => __DIR__ . '/../view/application/index/index.phtml',
            'error/404' => __DIR__ . '/../view/error/404.phtml',
            'error/index' => __DIR__ . '/../view/error/index.phtml',
        ),
        'template_path_stack' => array(
            __DIR__ . '/../view',
        ),
    )