Kohana 3 - redirect to 404 page

[亡魂溺海] 提交于 2019-12-11 11:59:36

问题


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


回答1:


Here is how we do it:

  1. 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().

  2. 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.




回答2:


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.



来源:https://stackoverflow.com/questions/5958157/kohana-3-redirect-to-404-page

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!