风格要求
//下划线风格,操作符两边空格,字符串单引号
$user_name = '王小名';
//双引号使用,中间引用的变量需加大括号
$info = "你的姓名:{$user_name}";
//函数 //大括号 , 参数列表空格
function eat_meat($type, $how_much) {
}
//数组风格
$some_things = array(
'name'=>'小小',
'sex'=>'石头'
);
//单行注释
/*
多行
注释
*/
/**
* 我是整个函数的说明
* @param string $a 我是a的说明
* @param int $b 我是b的说明
* @return int $c
*/
function im_func($a, $b){
return $c;
}
//类名首字母大写
//类采用最新的方式 不再有var 这种东西
class Person {
public $a = 1;
private function b() {
}
}
强制规定
- 代码风格强制使用上述规则
- 函数必须写注释
- 不得循环查询数据库
- 全局变量使用需通报所有人
- 不得在controller里查询数据库 调用Dao
- 不得在view层查询数据库
- 变量名不得出现拼音
- 变量名的长度超过3;
- 所有变量使用前须声明
- 前端过来的数据谨慎处理,第一时间考虑 注入和跨站的可能性
- bll层的方法 不允许出现 类似dao层的方法,需要有明确的意义
额外推荐
- 变量名超过5
- 不得对对象使用未声明的属性
- 待补充
- bll中的方法 尽量避免 get_xxx_by_where这种条件
AJAX返回数据格式
{
code: 0,1,2, //返回成功 统一取零
data: [] | {}, //需要返回的数据
message:"错误信息说明"
}
Swagger注释文档
swagger php参考地址案例。
Get方法
/**
* @OA\Get(
* path="/mp/fc",
* tags={"实地认证小程序"},
* summary="确认用户是否有权登录",
* @OA\Parameter(
* name="openid",
* in="query",
* description="openid",
* example="oKlGX5OlIfu3OaE21MXFxCOodexE",
* @OA\Schema(
* type="string"
* )
* ),
* @OA\Parameter(
* name="encryptedData",
* in="query",
* description="加密数据",
* @OA\Schema(
* type="string"
* )
* ),
* @OA\Response(
* response=200,
* description="OK"
* )
* )
*/
Post方法
/**
* @OA\Post(
* path="/mp/fc/action-ignore_item",
* tags={"实地认证小程序"},
* summary="提交实地认证放弃项目,真实地址/mp/fc",
* @OA\RequestBody(
* @OA\MediaType(
* mediaType="application/x-www-form-urlencoded",
* @OA\Schema(
* @OA\Property(
* property="action",
* type="string",
* default="submit_certification",
* description="ignore_item"
* ),
* @OA\Property(
* property="appoint_id",
* default="1",
* type="integer",
* description="预约id"
* ),
* @OA\Property(
* property="openid",
* type="string",
* default="oKlGX5OlIfu3OaE21MXFxCOodexE",
* description="微信openid"
* ),
* @OA\Property(
* property="main_type",
* default="1",
* type="string",
* description="1为环境,2为实力"
* ),
* @OA\Property(
* property="item_uuid",
* default="1",
* type="integer",
* description="预约uuid"
* )
* )
* )
* ),
* @OA\Response(
* response=200,
* description="OK"
* )
* )
*/