myzero1 / yii2-apibyconf
It is for api by yii2.
Installs: 1
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Type:yii2-module
Requires
- yiisoft/yii2: ~2.0
This package is not auto-updated.
Last update: 2024-12-21 06:39:15 UTC
README
You can generate restfull api by configuration.
Show time
Installation
The preferred way to install this module is through composer.
Either run
php composer.phar require myzero1/yii2-apibyconf:*
or add
"myzero1/yii2-apibyconf": "*"
to the require section of your composer.json
file.
Setting
Once the extension is installed, simply modify your application configuration as follows:
In 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' ], ]; ... } ...
In 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 ], ...... ] ...... ];
Usage
Selectable modules
- Set basePath to "/v2"
- Click the "Preview" button
- Click the "Generate" button, to Generate the codes.
- Set the config files
In 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', ], ], ], ...... ], ...... ];
- the
v2
will display to Selectable modules menu asv2 api
- you can click the
v2 api
button to config thev2
The other menu of apibyconfig
- you can click the
Swagger
button to use it. - you can click the
Markdown
button to use it.
change logs
- Add my group
- Carding code