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

About TP6 custom status code

藏色散人
Release: 2020-12-17 09:04:37
forward
2476 people have browsed it

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,
];
Copy after login

Use

config(&#39;code.success&#39;)
Copy after login

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);
}
Copy after login

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!

Related labels:
tp6
source:cnblogs.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template