smarteng/yii2-config

使用数据库管理Yii2配置

安装: 6

依赖者: 0

建议者: 0

安全: 0

星标: 0

关注者: 2

分支: 6

类型:yii2-extension

v1.0.6 2018-12-17 01:34 UTC

This package is auto-updated.

Last update: 2024-09-17 14:17:04 UTC


README

从数据库管理配置

安装

运行以下命令之一:

php composer.phar require --prefer-dist smarteng/yii2-config "*"

或者在您的composer.json文件的require部分添加:

"smarteng/yii2-config": "*"

smarteng/yii2-config

两个

应用迁移

yii migrate --migrationPath=@vendor/smarteng/yii2-config/migrations

配置

在配置文件中

'components' => [
    'config' => [
        'class' => '\smarteng\config\components\Config',
        'provider' => [
            'class' => '\smarteng\config\providers\DbProvider',
            'tableName' => '{{%config}}',  // by default
            'keyColumn' => 'key',                 // by default
            'valueColumn' => 'value',             // by default
        ]
    ],
    ...
]

创建自己的提供者

  1. 为提供者创建类
  2. 实现\smarteng\config\components\ConfigInterface
  3. 在您的提供者的配置文件中进行更改

用法

Db提供者示例

$isSet = \Yii::$app->config->set('commission', '10');   // can throw an exception
$isSet = \Yii::$app->config->safeSet('commission', '10');   // return false if something went wrong

$isSet = \Yii::$app->config->exists('commission');      // return true if key exists
$value = \Yii::$app->config->get('commission');         // return '10';

卸载

应用迁移

yii migrate/down --migrationPath=@vendor/smarteng/yii2-config/migrations