TP5把异常处理返回页面改成json格式
1、进入config.php,找到异常页面的模板文件,把路经改成自己一会要写的文件的路径,我写的是myException.tpl注意后缀名是.tpl。
默认是这样的
更改以后
2、可以看看think\exception\Handle.php的convertExceptionToResponse方法,大概了解一下他的模板文件的字是怎么来的。。
3、进入到thinkphp\tpl,模板文件就在这里啦,默认进去时这样的

那个think_exception.tpl就是tp5默认的异常处理输出页面了。我们加多一个myException.tpl(在config配置的是什么就加多一个什么)

我们看看tp5原来的是怎么写的
开头有一坨东西

html中,322和324行就是输出报错信息的,把它拷在自定义的tpl文件中(开头的一坨只要复制parse_file方法即可,不然不能用)
myException.tpl代码如下

然后故意弄错一个东西,比如在控制器中不引用Controller,返回异常如下