TP6 自定义状态码

config 目录下新建code.php

<?php
return [
    'success'=>1,
    'error'=>0,
    'need_login'=>-1,
    'user_is_registed'=>-2,
];

文件中使用 

config('code.success')

  统一api返回数据

common.php新建函数

<?php
// 应用公共文件
function show($code,$msg = "OK",$data = [],$httpCode = 200){

    $result = [
        'code'=>$code,
        'msg'=>$msg,
        'data'=>$data,
    ];
    return json($result,$httpCode);
}

猜你喜欢

转载自www.cnblogs.com/aln0825/p/12069121.html