toshcn / yii2-configurator
一个简单的配置管理组件
Installs: 10
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:yii2-extension
Requires
- yiisoft/yii2: ~2.0.0
This package is not auto-updated.
Last update: 2025-07-06 09:36:26 UTC
README
一个简单的配置管理组件
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'