Reputation: 11
After searching internet I haven't found answer to my question.
For example, in base complectation if you go to http://yoursite/welcome/
you'll see hello world
but if you type http://yoursite/welcom/ you'll see Fatal error: Uncaught HTTP_Exception_404 [ 404 ]: The requested URL welcom/index was not found on this server. ~ SYSPATH/classes/kohana/request/client/internal.php [ 94 ] thrown in
From here, how can I redirect user to 404 page if he type wrong address?
Kohana 3.1.3.1
Upvotes: 1
Views: 3431
Reputation: 5483
Here is how we do it:
Declare our own exception handler somewhere in bootstrap.php or module's init.php. Now all application exceptions will be sent to Kw_Exception_Handler::handle()
.
Exception handler analyses exception type (using getCode()
method) and creates a new HMVC request with special error controller, for example ('error/404').
Also you can add check for AJAX calls and return json structure with error text.
PS. This userguide tutorial may be helpful.
Upvotes: 3
Reputation: 191749
I think this will work for you: How to setup a custom 404 page for a Kohana v3 app
I think this is referring to Kohana 3, though. I think you need to use HTTP_Exception_???
and execute()
is called in index.php by default (by Request::factory()
, not Request::instance()
. I think you can work it out from there.
Upvotes: 1