Skip to content

toshcn/yii2-configurator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

yii2-configurator

一个简单的配置管理组件

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist toshcn/yii2-configurator "*"

or add

"toshcn/yii2-configurator": "*"

to the require section of your composer.json file.

Usage

配置组件:

'components' => [
    'config' => [
        'class' => 'toshcn\yii2\configurator\Configurator',
    ],
]

运行数据迁移:

php yii migrate --migrationPath=@vendor/toshcn/yii2-configurator/src/migrations

添加配置:基础模板在config->console.php,高级模板在console->config->main.php

Yii::$app->config->createConfig('myconfig', json_encode(['key' => 'value']), 'my first config');

获取配置项:

Yii::$app->config->getConfigItem('myconfig', 'key', 'defaultValue');
//返回 key对应的值 value, 如果key不存在,返回 'defaultValue'

获取全部配置项:

Yii::$app->config->getConfigItemAll('myconfig', ['key' => 'defaultValue']);
//返回 myconfig 配置的全部项, 可以指定配置项的默认值,如果key不存在,key的值会设为'defaultValue'

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages