1

如果在我的里面有一个 CheckModule.php并且需要抛出 Error 和 Redirect 到错误页面。

有人可以建议我如何处理这个问题吗?

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

}

}
4

1 回答 1

2

这应该可以解决问题,尽管它需要您在 module.config 中映射错误模板:

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

//and in module.config
'view_manager' => array(
    'display_exceptions'       => true,
    'exception_template'       => 'error/index',
于 2013-10-30T15:29:29.910 回答