ThinkPHP的404页面设定方式

2015-02-14 09:01:00

ThinkPHP中,某一个模块或方法不存在时,自定义404页面的方法

1、在Action目录中新建一个文件名为EmptyAction.class.php的文件

2、代码:

[php] view plaincopyprint?

  1. <?php
  2. class EmptyAction extends Action{
  3.  
  4.     //所请求的模块不存在时,默认执行的模块
  5.     public function index(){
  6.         header("HTTP/1.0 404 Not Found");//404状态码
  7.         $this->display("Common:404"); //显示自定义的404页面模版
  8.     }
  9.  
  10.     function _empty(){
  11.         header("HTTP/1.0 404 Not Found");//404状态码
  12.         $this->display("Common:404");//显示自定义的404页面模版
  13.     }
  14. }
  15. ?>
点赞

发表回复

电子邮件地址不会被公开。必填项已用 * 标注