【发布时间】:2015-08-07 07:08:16
【问题描述】:
我正在使用klein.php路由器,它真的很强大,但是现在我想处理异常, 所以从我正在使用这个功能的文档中看
$klein->onHttpError(function ($code, $router,$matched,$method_matched,$http_exception) {
switch ($code) {
case 404:
$router->response()->body(
'404 Page'
);
break;
case 405:
$router->response()->body(
'You can\'t do that!'
);
break;
default:
$router->response()->body(
'Oh no, a bad error happened that caused a '. $code
);
}
});
但是即使没有异常,这个函数也是在每一页的末尾渲染和打印404 page。
难道我做错了什么?我尝试检查$matched,但没有运气。
我想在错误处理中使用$service->render(),我该怎么做?因为服务无法访问,特别是onHttpError函数。
【问题讨论】:
标签: php exception-handling router klein-mvc