您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

分析 thinkphp5 显示render不兼容问题

2024/6/1 22:32:25发布30次查看
下面thinkphp框架教程栏目将给大家介绍关于tp5自定义全局异常处理提示render不兼容问题,希望对需要的朋友有所帮助!
【填坑】tp5自定义全局异常处理提示render不兼容tp5自定义全局异常处理,所有抛出的异常都通过自定义render方法渲染,再返回客户端显示。
需要自定义handle的render方法并覆盖:
namespace app\lib\exception;    use think\exception;  use think\exception\handle;class exceptionhandler extends handle  {    public function render(exception $e)      {          //todo:        return json('invalid request')    }  }
之后出现postman检验接口出现如下错误提示不兼容:
追踪到原始的handle.php文件,
查看下use,发现源文件用的是exception,而我用的think\exception:
修改下代码:
namespace app\lib\exception;    use exception;  use think\exception\handle;class exceptionhandler extends handle  {    public function render(exception $e)      {         //todo:        return json('invalid request')    }  }
结果正确啦:
推荐:《最新的10个thinkphp视频教程》
以上就是分析 thinkphp5 显示render不兼容问题的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product