tp框架设置404页面

//无法加载模板跳向404页面
/thinkphp/library/think/Dispatcher.class.php中176行
    // 加载模块的扩展配置文件
            load_ext_file(MODULE_PATH);
        }else{
            header("Location:/404.html");die;
            // E(L('_MODULE_NOT_EXIST_').':'.MODULE_NAME);
        }
//加上header跳转页面,404.html放在跟下


//无法加载控制器跳向404页面
//创建一个EmptyController.class.php 代码如下 
<?php
namespace Home\Controller;
use Think\Controller;
class EmptyController extends Controller
{
public function _empty(){
        $this->display('Error/404');//在Home/view中Error文件夹中
    }
}
//这样就行
//无法加载方法跳向404页面
//在/thinkphp/library/think/Controller.class.php在170行加上重跳转404页面
 public function __call($method,$args) {
        if( 0 === strcasecmp($method,ACTION_NAME.C('ACTION_SUFFIX'))) {
            if(method_exists($this,'_empty')) {
                // 如果定义了_empty操作 则调用
                $this->_empty($method,$args);
            }elseif(file_exists_case($this->view->parseTemplate())){
                // 检查是否存在默认模版 如果有直接输出模版
                $this->display();
            }else{
                $this->display('Error/404');
                // E(L('_ERROR_ACTION_').':'.ACTION_NAME);
            }
        }else{
            E(__CLASS__.':'.$method.L('_METHOD_NOT_EXIST_'));

    return;

  }

}

  

--------------------- 本文来自 大老王 的博客 ,转载至https://blog.csdn.net/sunxiaowen13/article/details/54943723

posted @ 2018-09-30 11:44  小ྀ青ྀ年້  阅读(774)  评论(0编辑  收藏  举报