myzero1 / yii2-apibyconf
这是一个为yii2 API提供的包。
1.0.1
2019-08-09 04:29 UTC
Requires
- yiisoft/yii2: ~2.0
This package is not auto-updated.
Last update: 2024-09-14 05:19:02 UTC
README
您可以通过配置生成restful API。
显示时间
安装
安装此模块的首选方式是通过 composer。
运行以下命令之一
php composer.phar require myzero1/yii2-apibyconf:*
或者
"myzero1/yii2-apibyconf": "*"
将以下内容添加到您的 composer.json
文件的require部分。
设置
一旦扩展被安装,只需按照以下方式修改您的应用程序配置
在 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\apibyconf\components\gii\generators\rest\Generator' ], ]; ... } ...
在 main.php 中
return [ ...... 'bootstrap' => [ ...... 'example', ...... ], ...... 'modules' => [ ...... 'example' => '\myzero1\apibyconf\example\ApiByConfModule',// should add table to db by 'example/models/user.sql' 'apibyconf' => 'myzero1\apibyconf\Module', ...... ], ...... 'components' => [ ...... 'user' => [ 'identityClass' => 'myzero1\apibyconf\components\rest\ApiAuthenticator', 'enableSession' => false, 'authTimeout' => 3600 * 24, // defafult 24h ], ...... ] ...... ];
用法
可选模块
- 设置 basePath 为 "/v2"
- 点击“预览”按钮
- 点击“生成”按钮,以生成代码。
- 设置配置文件
在 main.php 中
return [ ...... 'bootstrap' => [ ...... 'v1', ...... ], ...... 'modules' => [ ...... 'v1' => [ 'class' => 'backend\modules\v1\ApiByConfModule', 'docToken' => 'docTokenAsMyzero1', 'apiTokenExpire' => 24 * 3600 * 365, 'fixedUser' => [ 'id' => '1', 'username' => 'myzero1', 'api_token' => 'myzero1Token', ], 'runningAsDocActions' => [ // '*' => '*', // all ations, as default // 'controllerA' => [ // '*', // all actons in controllerA // ], // 'controllerB' => [ // 'actionB', // ], 'user' => [ 'create', 'index', ], ], ], ...... ], ...... ];
- 在“可选模块”菜单中,“v2”将显示为“v2 api”
- 您可以通过点击“v2 api”按钮来配置“v2”
apibyconfig的其他菜单
- 您可以点击“Swagger”按钮来使用它。
- 您可以点击“Markdown”按钮来使用它。
变更日志
- 添加我的组
- 卡片代码