In Kohana 2 you can override the default error page by creating a custom kohana_error_page.php file and putting it in your view directory. However, this overrides ALL errors not just 404's. In the case of 500 errors, I'd still like to get the friendly orange kohana error page.
Does anyone have experience in doing this?
I have not tested this!! So backup your code before you do this.
If I'm not mistaken, Kohana2 has hard-coded exception handling and there is no pretty way to add new exceptions. To work around that, you will have to make change in the core.
In the file
system/i18n/en_US/errors.php
add new entry:
In the file
system/i18n/en_US/core.php
add new entry:
In the
system/core/Koahana.php
:near the top of Kohana::setup() method, add new constant:
register the the event for your custom error ( somewhere near the end of same
Kohana::setup()
you will see registration for 404th error) :next, find the location for
Kohana::show_404()
and create you own method:scroll down to the bottom of the file .. there you will find the class definition for the
Error_404_Exception
... make one for403
. Don't forget to:protected $template = 'file_name_for_template';
protected $code = E_PAGE_ACCESS_DENIED;
Exception::__construct(Kohana::lang('core.page_access_denied', $page));
header('HTTP/1.1 403 Forbidden');
the template file will have to be located at system/views/
Now you should be able to call
Event::run('system.403');
from anywhere in the application.