输入banner图图片脚本导航/分类

Thinkphp6自定义状态码

下面由thinkphp框架教程栏目给大家介绍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);
}

以上就是Thinkphp6自定义状态码的详细内容,更多请关注gxlcms其它相关文章!