Home >PHP Framework >ThinkPHP >About TP6 custom status code
The following is an introduction to TP6 custom status codes from the thinkphp framework tutorial column. I hope it will be helpful to friends in need!
Create a new code.php in the config directory
<?php return [ 'success'=>1, 'error'=>0, 'need_login'=>-1, 'user_is_registed'=>-2, ];
Use
config('code.success')
unified api return data in the file
common.phpCreate a 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 About TP6 custom status code. For more information, please follow other related articles on the PHP Chinese website!