interface Hint {
function Error($_errors,$code);
}
class Template implements Hint{
function Error($_errors,$code) {
if (empty($_errors)) {
print_r(json_encode([]));
} else {
$errors['error']['name'] = 'Not Found';
$errors['error']['message'] = $_errors;
$errors['error']['error_code'] = $code;
print_r(json_encode($errors));
}
}
}
interface createMsg {
function Msg();
}
class FactoryMsg implements createMsg{
function Msg() {
return new Template;
}
}
class ErrorMsg {
// 抽象工厂里的静态方法
public static function Info($_errors) {
$Factory = new FactoryMsg;
$result = strstr($_errors,Yii::t('yii','Not exist')); //数据不存在 20001
$result1 = strstr($_errors,Yii::t('yii','Null')); //参数不能为空 20002
$result2 = strstr($_errors,Yii::t('yii','Fail')); //新增、更新、删除失败 20003
$result3 = strstr($_errors,Yii::t('yii','Not right')); //XX不正确 20004
$result4 = strstr($_errors,Yii::t('yii','Robc')); //XX无权限 20005
//数据不存在 20001
if(!empty($result)){
$M = $Factory->Msg();
$M->Error($_errors,'20001');die;
}
//参数不能为空 20002
if(!empty($result1)){
$M = $Factory->Msg();
$M->Error($_errors,'20002');die;
}
//新增、更新、删除失败 20003
if(!empty($result2)){
$M = $Factory->Msg();
$M->Error($_errors,'20003');die;
}
//XX不正确 20004
if(!empty($result3)){
$M = $Factory->Msg();
$M->Error($_errors,'20004');die;
}
//XX无权限 20005
if(!empty($result4)){
$M = $Factory->Msg();
$M->Error($_errors,'20005');die;
}
//默认类型 21000
$M = $Factory->Msg();
$M->Error($_errors,'21000');
}
}
use common\hint\error\ErrorMsg;
ErrorMsg::Info(Yii::t('yii','failure'));
{
"error": {
"name": "Not Found",
"message": "操作失败",
"error_code": "20003"
}
}
$result = strstr($_errors,Yii::t('yii','Not exist'));
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有