Home  >  Article  >  PHP Framework  >  Thinkphp6 custom status code

Thinkphp6 custom status code

藏色散人
藏色散人forward
2020-11-30 14:49:094329browse

The following thinkphp framework tutorial column will introduce you to the method of TP6 custom status code. I hope it will be helpful to friends in need!

Thinkphp6 custom status code

Use in the new code.php

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

file in the config directory

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

Unified api return data

common .php 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 Thinkphp6 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