代码
写入公共文件 tp>app>common.php
<?php
// 这是系统自动生成的公共文件
//function_exists('success')判断是否有这个文件
//成功时调用
if(!function_exists('success'))
{
function success($code,$mes,$data)
{
return json([
'code'=>$code,
'mes'=>$mes,
'data'=>$data,
]);
}
}
//失败时调用
if(!function_exists('error'))
{
function error($code,$mes,$data)
{
return json([
'code'=>$code,
'mes'=>$mes,
'data'=>$data,
]);
}
}
调用
//成功时调用
return success(200,'登录成功',null);
//失败时调用
return error(300,'登录失败',null);