The following thinkphp framework tutorial column will introduce you to the method of TP6 custom status code. I hope it will be helpful to friends in need!
Use in the new code.php
<?php return [ 'success'=>1, 'error'=>0, 'need_login'=>-1, 'user_is_registed'=>-2, ];
file in the config directory
config('code.success')
Unified api return data
common .php new function
<?php // 应用公共文件 function show($code,$msg = "OK",$data = [],$httpCode = 200){ $result = [ 'code'=>$code, 'msg'=>$msg, 'data'=>$data, ]; return json($result,$httpCode); }
The above is the detailed content of Thinkphp6 custom status code. For more information, please follow other related articles on the PHP Chinese website!