php规范

2019-01-11  本文已影响0人  nhsf
<?php
namespace app\exceptions\codes;

class UserExceptionCode extends BaseExceptionCode {
  const NO_AUTH       = 1000001;
  const NO_AUTH_MSG     = '不具有权限';
  const STATUS_EXCEPTION   = 1000002;
  const STATUS_EXCEPTION_MSG = '状态异常';    
}
<?php
namespace app\enums;

class UserEnum extends BaseEnum {
  const STATUS_DELETED = -1;// 已删除
  const STATUS_DISABLE = 0;// 禁用
  const STATUS_ENABLE = 1;// 正常

  const AUTH_GUEST     = 1;// 匿名用户
  const AUTH_GENERAL_ADMIN = 2;// 普通管理员
  const AUTH_SUPER_ADMIN  = 3;// 超级管理员
}

其中STATUS和AUTH为数据表映射字段名
Api接口输出,示例

{
  "code" : 0,
  "msg" : "success",
  "data" : {
    "userId" : 100
  }
}

其中code与msg为必填字段,data为空的情况下不填,示例

{
  "code" : 100001,
  "msg" : "不具有权限"
}
$arr = [ 'userId' => 100 ];

多个键时候使用多行,示例

$arr = [
  'id'    => 100,
  'username' => 'admin',
];
上一篇 下一篇

猜你喜欢

热点阅读