ZF2 - How to change the error/404 response page? Not just template but to set a new ViewModel

前端 未结 7 2526
离开以前
离开以前 2021-01-05 22:46

By default the page is set like this in the Application module.config array:

\'template_map\' => array(
    \'error/404\' => __DIR__ . \'/         


        
7条回答
  •  感情败类
    2021-01-05 23:43

    in module.php you can also change template and layout.

    function onBootstrap(EventInterface $e) {
      $app = $e->getApplication();
      $evt = $app->getEventManager();
      $evt->attach(MvcEvent::EVENT_DISPATCH_ERROR, array($this,'onDispatchError'), 100);    
    }
    
    function onDispatchError(MvcEvent $e) {
      $vm = $e->getViewModel();
      $vm->setTemplate('layout/blank');
    }
    

提交回复
热议问题