# linux-api-code-standard
**Repository Path**: luli7150/linux-api-code-standard
## Basic Information
- **Project Name**: linux-api-code-standard
- **Description**: 编码规范
- **Primary Language**: Unknown
- **License**: Not specified
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 1
- **Created**: 2024-09-30
- **Last Updated**: 2024-09-30
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# linux-api-code-standard
#### CI4 编码规范
一. 传参使用说明
1.uri传参: $id/$state
http://144.34.181.85/appstarter/index.php/admin/set_state/2/3
2.query参数: ?ifname=eth0¤t=1&pagesize=15
http://144.34.181.85/appstarter/index.php/admin/query_search?ifname=eth0¤t=1&pagesize=15
3.json参数: {"name":"admin","password":"123456"}
http://144.34.181.85/appstarter/index.php/admin/json_add
4.无参数:
http://144.34.181.85/appstarter/index.php/admin/db_test
二. 文件夹/类/函数编写说明
1,控制器文件夹大写: Admin
2,类名单词首字母大写: MyTest
3,函数接口名一律小写: index,query_search
4,路由映射接口api路径一律小写: /admin/json_add
三. 返回值说明
1,返回值一律使用数组转json
2,数组必须的字段
\$$result['success'] = 1; //结果返回成功
\$result['code'] = 200; //http相应成功
\$result['msg'] = "xxxx"; //消息说明
3,转换字符串返回给浏览器
json_encode(\$result, JSON_UNESCAPED_UNICODE)
四. 数据库规范
1,一律使用构建器获取数据,尽量不使用sql语句查询
2, 获取的数据一律转换成数组
#### 系统平台
1, 系统os:
openEuler-22.03 sp3
2, 前置软件:
yum install httpd mariadb-server php php-intl php-mysqlnd
3, codeigniter4 中文手册
http://codeigniter.org.cn/user_guide/database/queries.html
#### 软件搭建
1,软件安装
curl -s http://getcomposer.org/installer | php
mv composer.phar /usr/bin/composer
#切换镜像(https://cloud.tencent.com/developer/article/1464303)
composer config -g repos.packagist composer https://mirrors.aliyun.com/composer/
2,下载项目(ci4框架最新版本下载,目录为appstarter ,直接重命名 api)
composer create-project codeigniter4/appstarter api
composer create-project codeigniter4/appstarter:4.4.8 appstarter(推荐)
如果报错,可能缺少php依赖
yum install php-xml
yum install php-mbstring
cd api
composer install #根据项目composer.json文件,自动安装依赖
composer install --ignore-platform-req=ext-intl #忽略ext-intl包,否则安装不成功
3,启动服务(http://localhost:8080)
php spark serve
php spark serve --host 0.0.0.0 --port 8080