Home > PHP Framework > ThinkPHP > Thinkphp6 custom status code

Thinkphp6 custom status code

藏色散人
Release: 2020-11-30 14:49:09
forward
4403 people have browsed it

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

file in the config directory

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

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

The above is the detailed content of Thinkphp6 custom status code. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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