公司代码规范

it2022-05-05  99

xcore框架目录

├─vendor 扩展目录(在这个目录可以使用composer 安装插件) ├─library 框架核心目录 │ ├─db 封装的底层数据库操作类 │ ├─my 封装常用功能静态类 │ ├─Function.php 通用函数 │ ├─G.php 全局变量 ├─common 通用模型(涉及到数据库)

框架支持:

命名空间,支持composer多域名部署分布式环境支持(cookie入库)php7以上mysqli

项目目录结构

www WEB部署目录 ├─application 应用目录 │ ├─autoload 自动加载 │ │ ├─function.php 项目函数文件 │ ├─common 公共模型目录 │ │ ├─model 业务模型(不用事务) │ │ ├─server 业务模型(使用事务) │ ├─config 配置目录 │ │ ├─adminmenu.php 后台目录配置文件 │ │ ├─type.php 业务配置文件 │ ├─admin 后台模块 │ ├─www 前台模块 ├─public WEB目录(对外访问目录) │ ├─static 静态文件目录 │ ├─index.php 入口文件 │ └─.htaccess 用于apache的重写

编写规范

命名原则, 能够表达语义. 选择简单的单词目录小写;所有Php文件,首字母大写, 里面的类名和文件名保持一致函数名称, 下划线/驼峰.数据库建表规范,表名用常用英文单词. 索引固定写id, 关联字段,用关联表加下划线id业务配置规范, 数据库表名_字段名 (简单通用的可以直接用简写)controller名称与数据库表保持一致controller固定方法名称, lists, add, edit, detail, del, delall模板和提交数据共用一个方法名称 用is_post() 函数区分开

程序文件目录

controller: 参数验证, 代码业务逻辑 model: 封装复杂的业务逻辑 server: 有事务的业务逻辑 view: 模板

服务器图片处理

每次编辑,更新,删除都要对业务的图片进行处理

#添加/编辑文章时, 处理文章图片, $d是文章入库字段 m('Attachment','xcom')->imgSure('article',$id,$d); #删除文章,同时删除图片 m('Attachment','xcom')->imgDel('article',$d['id'],true);

调用模型

#调用非事务模型 m(模型名称, 'c')->方法名称(); #调用事务模型 s(模型名称, 'c')->方法名称();

db函数的使用

#组装条件搜索 $map = [['and','id','=', 1]]; $w = where($map); $rs = $this->db->query("select * from user $w[0]",$w[1]); #搜索多条 $rs = $this->db->query("select * from user where status=?",[0]); #搜索单条 $rs = $this->db->query("select * from user where status=?",[0],1); #插入数据 $data = ['name'=>'张三', 'status'=>0]; $id = $this->db->insert('user', $data); #更新数据 $data = ['id'=>1,'name'=>'张三', 'status'=>0]; $this->db->update('user', $data); #搜索多条,并返回数据库总条数 $rs = $this->db->query("select * from user where status=?",[0],'',true); #快捷方法 find, update, select, insert, insertAll #sql快捷方式,使用时注意他们的参数

显示模板

$this->fetch([键值对]);

验证参数

$d = $this->post; $rule = [ 'title'=>'require', ]; $msg = [ 'title.require'=>'请填写标题', ]; check($rule,$msg,$d);

post返回函数

if(is_post()){ suc([键值对数据]);#成功返回 err('错误提示语句');#失败返回 }

注意事项

1,数据库全部使用 $this->db; 不要使用db()函数否则导致事务失败2,controller 一定要验证表单3,涉及到图片的表单一定要使用通用附件模型. Attachment. 否则图片会被删除4, 复用的, 逻辑比较多的, 涉及事务的. 要写成server

代码协作使用git

git init git add remote xxx master git add . git commit -m '修改备注' git pull xxx master git push xxx master git branch v2

具体使用,内部团队沟通.... xcore® 版权所有 xielisen。

转载于:https://www.cnblogs.com/xielisen/p/8555067.html


最新回复(0)