PHPackages                             myzero1/yii2-restbyconf - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. myzero1/yii2-restbyconf

ActiveYii2-module[API Development](/categories/api)

myzero1/yii2-restbyconf
=======================

Ti is for restful api by yii2.

v2.3.3(6y ago)0748MITPHP

Since Apr 2Pushed 2mo agoCompare

[ Source](https://github.com/myzero1/yii2-restbyconf)[ Packagist](https://packagist.org/packages/myzero1/yii2-restbyconf)[ RSS](/packages/myzero1-yii2-restbyconf/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (10)Dependencies (2)Versions (56)Used By (0)

yii2-restbyconf
===============

[](#yii2-restbyconf)

You can generate restfull api by configuration.

Show time
---------

[](#show-time)

[![](https://github.com/myzero1/show-time/raw/master/yii2-restbyconf/screenshot/104.png)](https://github.com/myzero1/show-time/blob/master/yii2-restbyconf/screenshot/104.png)[![](https://github.com/myzero1/show-time/raw/master/yii2-restbyconf/screenshot/102.png)](https://github.com/myzero1/show-time/blob/master/yii2-restbyconf/screenshot/102.png)[![](https://github.com/myzero1/show-time/raw/master/yii2-restbyconf/screenshot/103.png)](https://github.com/myzero1/show-time/blob/master/yii2-restbyconf/screenshot/103.png)

Installation
------------

[](#installation)

The preferred way to install this module is through [composer](http://getcomposer.org/download/).

Either run

```
php composer.phar require myzero1/yii2-restbyconf：*

```

or add

```
"myzero1/yii2-restbyconf": "*"

```

to the require section of your `composer.json` file.

Setting
-------

[](#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\restbyconf\components\gii\generators\rest\Generator'
        ],
    ];
    ...
}
...
```

`In 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
        ],
        ......
    ]
    ......
];
```

Usage
-----

[](#usage)

### Selectable modules

[](#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' => [
        ......
        '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',
                // ],
            ],
        ],
        ......
    ],
    ......
];
```

- the `v2` will display to Selectable modules menu as `v2 api`
- you can click the `v2 api` button to config the `v2`
- you can add `response_code` param to return characteristic return

### The other menu of restbyconfig

[](#the-other-menu-of-restbyconfig)

- you can click the `Swagger` button to use it.
- you can click the `Markdown` button to use it.

### Can overwrite classes

[](#can-overwrite-classes)

- myzero1\\restbyconf\\components\\rest\\Helper
- myzero1\\restbyconf\\components\\rest\\ApiHelper
- myzero1\\restbyconf\\components\\rest\\ApiAuthenticator
- myzero1\\restbyconf\\components\\rest\\HandlingHelper

`In 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';
        },
        ......
    ],
    ......
];
```

### change logs

[](#change-logs)

- Add my group
- Carding code
- Multiple responses

### TODO

[](#todo)

- $modelPost-&gt;addRule(\['mobile\_phone'\], 'required', \['message' =&gt; ''{attribute}':手机号不能为空'\]);

###  Health Score

42

—

FairBetter than 89% of packages

Maintenance58

Moderate activity, may be stable

Popularity15

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity74

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~60 days

Recently: every ~589 days

Total

44

Last Release

60d ago

Major Versions

1.6.0 → 2.0.02019-05-10

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/22048203?v=4)[myzero1](/maintainers/myzero1)[@myzero1](https://github.com/myzero1)

---

Top Contributors

[![myzero1](https://avatars.githubusercontent.com/u/22048203?v=4)](https://github.com/myzero1 "myzero1 (659 commits)")

### Embed Badge

![Health badge](/badges/myzero1-yii2-restbyconf/health.svg)

```
[![Health](https://phpackages.com/badges/myzero1-yii2-restbyconf/health.svg)](https://phpackages.com/packages/myzero1-yii2-restbyconf)
```

###  Alternatives

[craftcms/cms

Craft CMS

3.6k3.6M2.9k](/packages/craftcms-cms)[skeeks/yii2-google-api

Component for work with google api based on google/apiclient

1143.6k1](/packages/skeeks-yii2-google-api)[apexwire/yii2-restclient

Tools to use API as ActiveRecord for Yii2

133.5k](/packages/apexwire-yii2-restclient)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
