美文网首页
tp5自定义 异常处理 页面

tp5自定义 异常处理 页面

作者: geeooooz | 来源:发表于2017-12-29 15:25 被阅读2935次

    异常☞类似以下这种

    那么在调试好的运行中的网站 大家一定不会想要见到这种错误吧 (用户体验在哪里)

    接下来就告诉大家如何 通过配置自定义类来 跳转404错误页面


    1.关闭所有app_debug 即 'app_debug' => true,

    2.在config.php中配置自定义类

      'exception_handle'       => '\\app\\common\\exception\\Http',
    

    3.创建类 入下图创建文件夹及文件


    4.在Http.php中写入

    <?php
    namespace app\common\exception;
    
    use Exception;
    use think\exception\Handle;
    class Http extends Handle
    {
    
        public function render(\Exception $e){
            if(config('app_debug')){
                            //如果开启debug则正常报错
                return parent::render($e);
            }else{
                            //404页面  自行定义
                header("Location:".url('home/index/index'));
            }
        }
    
    }
    

    现在 可以通过关闭/开启debug来实现404/报错了

    相关文章

      网友评论

          本文标题:tp5自定义 异常处理 页面

          本文链接:https://www.haomeiwen.com/subject/wygigxtx.html