exchangecore/yii2-config

Configuration components for Yii2

Installs: 2

Dependents: 0

Suggesters: 0

Security: 0

Type:yii2-extension

dev-master 2015-03-25 21:16 UTC

This package is auto-updated.

Last update: 2019-03-18 16:04:04 UTC


README

First you must install the extension using composer. To do so simply add it to your application's composer.json like so:

"require": {
    "exchangecore/yii2-config": "dev-master",
},

To set up a configuration repository you should use something similar to below in your yii configuration file. The db and table properties are optional. You MUST name the component 'config' for the DbRepository to work.

'components' => [
    'config' => [
        'class' => 'exchangecore\config\components\DbRepository',
        // 'db' => 'db',
        // 'table' => 'Config'
    ]
],
'modules' => [
    'config' => ['class' => 'exchangecore\config\Module'],
],

Before you can leverage the DbRepository you must install the table. To do so run the following from the command line:

php yii migrate --migrationPath="@exchangecore/config/migrations"

Now you can start saving and getting values from your configuration component like so:

//to save a configuration value
\Yii::$app->config->save('namespace::group.item.item1', $value);
\Yii::$app->config->save('namespace::group.item.item2', $value2);

//to retrieve a configuration value
\Yii::$app->config->get('namespace::group.item.item1'); //returns $value
\Yii::$app->config->get('namespace::group.item'); //returns array('item1' => $value, 'item2' => $value2)

Thanks To

Most of what you'll find in this extension/module is a version of what is used by Concrete5 and Illuminate.