使用kohana修改http404错误返回提示页面

来源:互联网 发布:gm300写频软件 编辑:程序博客网 时间:2024/04/30 14:18


kohana使用system.404 事件来返回404的http错误。所以要修改此事件的回调函数,event是在kohana运行前设置。要想修改event,必须在event配置执行前修改,而hook是在event前执行的,所以使用hook修改event,修改event的system.404事件来显示用户自定义的页面提示。有关event和hook的知识请参考kohana官方文档点击打开链接。

例子。

1,在hooks添加show_404.php

class Show_404 {public function show(){    Kohana::show_404(false,'template/user_defined_404');}}Event::replace('system.404', array('Kohana', 'show_404'), array('Show_404', 'show'));
这样当发生404的http错误时就会显示template/user_defined_404_api.html页面了。

2,写template/user_defined_404_api.html页面。