yii2-configurator
一个简单的配置管理组件, (*1)
Installation
The preferred way to install this extension is through composer., (*2)
Either run, (*3)
php composer.phar require --prefer-dist toshcn/yii2-configurator "*"
or add, (*4)
"toshcn/yii2-configurator": "*"
to the require section of your composer.json
file., (*5)
Usage
配置组件:, (*6)
'components' => [
'config' => [
'class' => 'toshcn\yii2\configurator\Configurator',
],
]
运行数据迁移:, (*7)
php yii migrate --migrationPath=@vendor/toshcn/yii2-configurator/src/migrations
添加配置:基础模板在config->console.php,高级模板在console->config->main.php, (*8)
Yii::$app->config->createConfig('myconfig', json_encode(['key' => 'value']), 'my first config');
获取配置项:, (*9)
Yii::$app->config->getConfigItem('myconfig', 'key', 'defaultValue');
//返回 key对应的值 value, 如果key不存在,返回 'defaultValue'
获取全部配置项:, (*10)
Yii::$app->config->getConfigItemAll('myconfig', ['key' => 'defaultValue']);
//返回 myconfig 配置的全部项, 可以指定配置项的默认值,如果key不存在,key的值会设为'defaultValue'