ThinkPHP3.2如何设置404跳转页面

来源:互联网 发布:网络有什么负面影响 编辑:程序博客网 时间:2024/05/17 06:04

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



2方法2   
<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {
-------------中插入***-----------
    public function _empty(){
    echo 'xxxx';
}

}
0 0