sersid/yii2-config Yii2 manage configuration from database

extensionconfig

Yii2 Config

Manage configuration from database

Installation

One

The preferred way to install this extension is through composer.

Either run

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

or add

"sersid/yii2-config": "*"

to the require section of your composer.json file.

Two

Applying migrations

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

Three

$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
        ],
    ]
];

Usage

Once the extension is installed, simply use it in your code by :

Set

Yii::$app->config->set('foo', 'bar');
Yii::$app->config->set('foo', ['bar', 'baz']);
Yii::$app->config->set(['foo' => 'bar']);

Get

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']);

Delete

Yii::$app->config->delete('foo');
Yii::$app->config->deleteAll(); // delete all config

Uninstall

Applying migrations

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

Statistics

Downloads
GitHub Stars
GitHub Forks

Releases

Comments



v1.0.3 is the latest of 4 releases



BSD-3-Clause license
Stats
4 github stars & 6 github forks
0 downloads in the last day
0 downloads in the last 30 days
2323 total downloads