兵兵有你

人品好,气质差.丢了工作就回家...

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

重点定义自己的错误信息和错误码;

在TP5的配置文件中有下面一段

// 异常处理handle类 留空使用 \think\exception\Handle

'exception_handle'       => '',
指错误信息来自自于\think\exception\Handle的方法里;那么可以重新定义一个类,再重写这个hander方法即可;
======================================
1.定义config:
'exception_handle'       => 'app\lib\exception\ExceptionHandler',
2.在app\lib\exception\ExceptionHander.php中:
class ExceptionHandler extends Handle
{
    public function render(Exception $e)
    {
        return json('这里是自定义的错误');
        //return parent::render($e); // TODO: Change the autogenerated stub

    }
}

 

posted on 2017-12-28 15:21  greatbing  阅读(2298)  评论(0编辑  收藏  举报