myzero1 / yii2-restbyconf
Ti 是基于 yii2 的 restful api。
v2.3.3
2019-11-11 09:58 UTC
Requires
- myzero1/yii2-smser: *
- yiisoft/yii2: ~2.0
- dev-master
- v2.3.3
- v2.3.2
- v2.3.1
- v2.3.0
- 2.2.20.05
- 2.2.20.04
- 2.2.20.03
- 2.2.20.02
- 2.2.20.01
- 2.2.11
- 2.2.2.01
- 2.2.2
- v2.2.01
- 2.2.0.1
- 2.2.0
- 2.1.7.1
- 2.1.7
- 2.1.6
- 2.1.5
- 2.1.4
- 2.1.3
- 2.1.2
- 2.1.1
- 2.1.0
- 2.0.8
- 2.0.7.1
- 2.0.7
- 2.0.6
- 2.0.5
- 2.0.4
- 2.0.3
- 2.0.2
- 2.0.1
- 2.0.0
- 1.6.0
- 1.5.0
- 1.4.0
- 1.3.0
- 1.2.0
- 1.1.0
- 1.0.0
- dev-feature/2.1.7
- dev-develop
- dev-feature/2.2.20.04.01
- dev-hotfix/fix-last-space-line
- dev-hotfix/fix-complete-result
- dev-feature/fix-mult-member
- dev-feature/2.0.7.1
- dev-feature/2.2.x
- dev-feature/2.2.0x
- dev-hotfix/fix-some-bugs
- dev-feature/add-authorize
This package is not auto-updated.
Last update: 2024-09-11 12:55:11 UTC
README
您可以通过配置来生成 restful api。
显示时间
安装
安装此模块的首选方式是通过 composer。
运行以下命令之一:
php composer.phar require myzero1/yii2-restbyconf:*
或者添加以下内容到您的 composer.json
文件的 require 部分:
"myzero1/yii2-restbyconf": "*"
设置
扩展安装完成后,只需按以下方式修改您的应用程序配置:
在 main-local.php 中
... if (!YII_ENV_TEST) { // configuration adjustments for 'dev' environment ... $config['bootstrap'][] = 'gii'; $config['modules']['gii'] = [ 'class' => 'yii\gii\Module', ]; $config['modules']['gii']['generators'] = [ 'rest' => [ 'class' => 'myzero1\restbyconf\components\gii\generators\rest\Generator' ], ]; ... } ...
在 main.php 中
return [ ...... 'bootstrap' => [ ...... 'example', 'v1', ...... ], ...... 'modules' => [ ...... 'restbyconf' => 'myzero1\restbyconf\Module', 'example' => [ 'class' => 'myzero1\restbyconf\example\RestByConfModule',// should add table to db by 'yii2-restbyconf/src/user.sql' 'apiTokenExpire' => 24 * 3600 * 365, 'fixedUser' => [ 'id' => '1', 'username' => 'myzero1', 'api_token' => 'myzero1Token', ], 'smsAndCacheComponents' => [ 'captchaCache' => [ 'class' => '\yii\caching\FileCache', 'cachePath' => '@runtime/captchaCache', ], 'captchaSms' => [ 'class' => 'myzero1\smser\QcloudsmsSmser',// 腾讯云 'appid' => '1400280810', // 请替换成您的appid 'appkey' => '23e167badfc804d97d454e32e258b780', // 请替换成您的apikey 'smsSign' => '玩索得', 'expire' => '5',//分钟 'templateId' => 459670, // 请替换成您的templateId ], ], 'runningAsDocActions' => [ '*' => '*', // all ations, as default // 'controllerA' => [ // '*', // all actons in controllerA // ], // 'controllerB' => [ // 'actionB', // ], ], ], ...... ], ...... 'components' => [ ...... // 'assetManager' => [ // 'class' => 'yii\web\AssetManager', // 'forceCopy' => true,// true/false // ], 'user' => [ 'identityClass' => 'myzero1\restbyconf\components\rest\ApiAuthenticator', 'enableSession' => false, 'authTimeout' => 3600 * 24, // defafult 24h ], ...... ] ...... ];
使用方法
可选模块
- 将 basePath 设置为 "/v2"
- 点击“预览”按钮
- 点击“生成”按钮,以生成代码。
- 设置配置文件
在 main.php 中
return [ ...... 'bootstrap' => [ ...... 'v2', ...... ], ...... 'modules' => [ ...... 'v2' => [ 'class' => 'api\modules\v2\RestByConfModule', 'apiTokenExpire' => 24 * 3600 * 365, 'fixedUser' => [ 'id' => '1', 'username' => 'myzero1', 'api_token' => 'myzero1Token', ], 'smsAndCacheComponents' => [ 'captchaCache' => [ 'class' => '\yii\caching\FileCache', 'cachePath' => '@runtime/captchaCache', ], 'captchaSms' => [ 'class' => 'myzero1\smser\QcloudsmsSmser',// 腾讯云 'appid' => '1400280810', // 请替换成您的appid 'appkey' => '23e167badfc804d97d454e32e258b780', // 请替换成您的apikey 'smsSign' => '玩索得', 'expire' => '5',//分钟 'templateId' => 459670, // 请替换成您的templateId ], ], 'runningAsDocActions' => [ '*' => '*', // all ations, as default // 'controllerA' => [ // '*', // all actons in controllerA // ], // 'controllerB' => [ // 'actionB', // ], ], ], ...... ], ...... ];
- 在“可选模块”菜单中,“v2”将显示为“v2 api”
- 您可以点击“v2 api”按钮来配置“v2”
- 您可以添加“response_code”参数来返回特性返回值
restbyconfig 的其他菜单
- 您可以点击“Swagger”按钮来使用它。
- 您可以点击“Markdown”按钮来使用它。
可以覆盖类
- myzero1\restbyconf\components\rest\Helper
- myzero1\restbyconf\components\rest\ApiHelper
- myzero1\restbyconf\components\rest\ApiAuthenticator
- myzero1\restbyconf\components\rest\HandlingHelper
在 main.php 中
return [ ...... 'bootstrap' => [ ...... 'classMap' => function(){ Yii::$classMap['myzero1\restbyconf\components\rest\Helper'] = '@app/modules/v1/components/Helper.php'; Yii::$classMap['myzero1\restbyconf\components\rest\ApiHelper'] = 'path/to/ApiHelper.php'; }, ...... ], ...... ];
变更日志
- 添加我的小组
- 卡片代码
- 多个响应
待办事项
- $modelPost->addRule(['mobile_phone'], 'required', ['message' => '{attribute}':手机号不能为空']);