简体   繁体   中英

ZF2 How to show an error 404 for nonexistant actions

I have a large site based on Zend Framework 2. URLs follow the standard pattern of domain.tld/module/action/otherstuff.

If someone types in a module that does not exist, they get a standard 404 page not found message. However, if the user goes to a valid module but enters an invalid action name, they get a message

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

How can I output a normal 404 error message instead of this message? I am guessing I am not catching something correctly somewhere, but I don't know where to start looking.

Here is the stack trace:

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}            

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',
        ),
    )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM