我如何处理Kohana 3.3中的每个错误?我的意思是没有404/505错误但是来自php和其他php的错误的"致命错误"?
我查看了http://kohanaframework.org/3.3/guide/kohana/tutorials/error-pages并且我做了这些事情,但是它只处理了404/505错误(以及其他错误).我无法处理500错误.
我创建文件/APP/Classes/HTTP/Exception/500.php
class HTTP_Exception_500 extends Kohana_HTTP_Exception_500 {
public function get_response()
{
$session = Session::instance();
$view = View::factory('index');
$view->content = View::factory('errors/505');
$view->title = 'Wewn?trzny b??d';
// Remembering that `$this` is an instance of HTTP_Exception_404
$view->content->message = 'Wyst?pi? wewn?trzny b??d. Szczegó?y zosta?y przekazane do administracji, naprawimy to!';
$response = Response::factory()
->status($this->getCode())
->body($view->render());
return $response;
}
Run Code Online (Sandbox Code Playgroud)
但它不起作用..谢谢:)
"自定义错误页面将仅用于处理抛出HTTP_Exception.如果您只是通过Respose :: status()设置状态,例如404,则不会使用自定义页面." - 您链接的教程.
调用HTTP_Exception :: get_response()的代码位于Request_Client_Internal :: request_execute()中.
要处理其他异常,您需要覆盖Kohana_Exception :: response().这样的事情应该有效.
<?php defined('SYSPATH') OR die('No direct script access.');
class Kohana_Exception extends Kohana_Kohana_Exception {
/**
* Generate a Response for all Exceptions without a more specific override
*
* The user should see a nice error page, however, if we are in development
* mode we should show the normal Kohana error page.
*
* @return Response
*/
public static function response(Exception $e)
{
if (Kohana::$environment >= Kohana::DEVELOPMENT)
{
// Show the normal Kohana error page.
return parent::response();
}
$view = View::factory('index');
$view->content = View::factory('errors/500');
$view->title = 'Wewn?trzny b??d';
$view->content->message = 'Wyst?pi? wewn?trzny b??d. Szczegó?y zosta?y przekazane do administracji, naprawimy to!';
$response = Response::factory()
->status(500)
->body($view->render());
return $response;
}
}
Run Code Online (Sandbox Code Playgroud)