ser sid / yii2-config
使用数据库管理Yii2配置
v1.0.3
2015-03-06 09:25 UTC
Requires
- yiisoft/yii2: *
This package is not auto-updated.
Last update: 2024-09-24 03:23:29 UTC
README
从数据库管理配置
安装
一
安装此扩展的首选方式是通过 composer。
运行以下命令之一:
php composer.phar require --prefer-dist sersid/yii2-config "*"
或者
"sersid/yii2-config": "*"
将以下内容添加到您的 composer.json
文件的require部分。
二
应用迁移
yii migrate --migrationPath=@vendor/sersid/yii2-config/migrations
三
$config = [ ... 'components' => [ ... 'config' => [ 'class' => 'sersid\config\components\Config', 'coding' => '...', // json of serialize. Default 'json' 'idConnection' => 'db', // The ID of the connection component 'tableName' => '{{%config}}', //Config table name 'idCache' => 'cache', // The ID of the cache component. Default null (no caching) 'cacheKey' => 'config.component', // The key identifying the value to be cached 'cacheDuration' => 360, // The number of seconds in which the cached value will expire. 0 means never expire. Default 0 ], ] ];
用法
扩展安装后,只需在代码中使用即可
设置
Yii::$app->config->set('foo', 'bar'); Yii::$app->config->set('foo', ['bar', 'baz']); Yii::$app->config->set(['foo' => 'bar']);
获取
Yii::$app->config->get('zyx'); // null Yii::$app->config->get('zyx', 'default'); // 'default' Yii::$app->config->get('foo', 'default'); // 'bar' Yii::$app->config->get(['foo' => 'default']);
删除
Yii::$app->config->delete('foo'); Yii::$app->config->deleteAll(); // delete all config
卸载
应用迁移
yii migrate/down --migrationPath=@vendor/sersid/yii2-config/migrations