Zend framework2 ZF2在Module.php内抛出错误和重定向

Zend framework2 ZF2在Module.php内抛出错误和重定向,zend-framework2,Zend Framework2,如果在myModule.php中进行检查,需要抛出错误并重定向到错误页面 有人能告诉我怎么处理这件事吗 $eventManager->attach(MvcEvent::EVENT_ROUTE, function ($e) use($serviceManager, $capture) { if($foo == null) { throw new \Exception(" } } 虽然这需要在module.config中映射错误模板,但应该可以做到这一点: $

如果在my
Module.php
中进行检查,需要抛出错误并重定向到错误页面

有人能告诉我怎么处理这件事吗

$eventManager->attach(MvcEvent::EVENT_ROUTE, function ($e) use($serviceManager, $capture)
        {
   if($foo == null) {
   throw new \Exception("

}

}

虽然这需要在module.config中映射错误模板,但应该可以做到这一点:

$response = $e->getResponse();
$response->setStatusCode(500);
$response->sendHeaders();

//and in module.config
'view_manager' => array(
    'display_exceptions'       => true,
    'exception_template'       => 'error/index',