config 目录下新建code.php
return [
'success'=>1,
'error'=>0,
'need_login'=>-1,
'user_is_registed'=>-2,
];
文件中使用
config('code.success')
统一api返回数据
common.php新建函数
// 应用公共文件
function show($code,$msg = "OK",$data = [],$httpCode = 200){
$result = [
'code'=>$code,
'msg'=>$msg,
'data'=>$data,
];
return json($result,$httpCode);
}
本文来自PHP中文网,原文地址:https://www.php.cn/phpkj/thinkphp/466555.html 推荐教程:《thinkphp》
网友评论