Home >PHP Framework >ThinkPHP >About TP6 custom status code

About TP6 custom status code

藏色散人
藏色散人forward
2020-12-17 09:04:372474browse

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!

About TP6 custom status codeCreate a new code.php in the config directory

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

Use

config(&#39;code.success&#39;)

unified api return data in the file

common.phpCreate a new Function

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

    $result = [
        &#39;code&#39;=>$code,
        &#39;msg&#39;=>$msg,
        &#39;data&#39;=>$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!

Statement:
This article is reproduced at:cnblogs.com. If there is any infringement, please contact admin@php.cn delete