myzero1/yii2-apibyconf

It is for api by yii2.

Maintainers

๐Ÿ‘ myzero1

Package info

github.com/myzero1/yii2-apibyconf

Type:yii2-module

pkg:composer/myzero1/yii2-apibyconf

Statistics

Installs: 1

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

1.0.1 2019-08-09 04:29 UTC

Requires

Requires (Dev)

None

Suggests

None

Provides

None

Conflicts

None

Replaces

None

MIT 09ddeca544c260b41027eca323968afe318b6762

  • Xuanwu Qin <myzero1.woop@sina.com>

This package is not auto-updated.

Last update: 2026-06-20 13:34:01 UTC


README

You can generate restfull api by configuration.

Show time

๐Ÿ‘ Image
๐Ÿ‘ Image
๐Ÿ‘ Image

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 as v2 api
  • you can click the v2 api button to config the v2

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