我正在为 Kohana 编写一个错误处理程序。有一个控制器Controller_Errors
(它继承Controller_Kohana_Errors
),其动作包括action_404
、action_403
、action_500
等。
路线:
Route::set('errors','errors/<action>', array (
'action' => '[\d]{3}',
))
->defaults(array(
'controller' => 'errors',
));
包括示例 bootstrap.php
try {
$response = Request::factory()->execute();
} catch (Exception $e) {
// If we are in development and the error wasn't a 404, show the stack trace.
// Otherwise, show a nice error.
if ((Kohana::$environment == KOHANA::DEVELOPMENT) AND ( ! ($e->getCode() == 404 OR $e->getCode() == 403))) {
throw $e;
}
// Log the error
Kohana::$log->add(Log::ERROR, Kohana_Exception::text($e));
$error_code = 500;
if ($e instanceof ReflectionException) {
$error_code = 404;
}
if ($e instanceof HTTP_Exception)
{
$error_code = $e->getCode();
}
$request = Request::factory('errors/'.$error_code);
if (*__NOT SURE WHAT GOES HERE__*) {
$request = Request::factory('errors/500');
}
$response = $request->execute();
}
// Send the headers and echo the response
echo $response->send_headers()->body();
我想让人们扩展我的课程,所以我需要一些方法来检查一个动作是否存在,如果不存在,则更改为显示 500 错误。(参见上面写着的那一行*__NOT SURE WHAT GOES HERE__*
。)