smarteng/yii2-config

Yii2 manage config from database

Installs: 6

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 2

Forks: 6

Type:yii2-extension

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

This package is auto-updated.

Last update: 2024-04-17 13:17:34 UTC


README

Manage configuration from database

Installation

Either run

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

or add

"smarteng/yii2-config": "*"

to the require section of your composer.json file.

Two

Applying migrations

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

Configuration

In configuration file

'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
        ]
    ],
    ...
]

Create own provider

  1. Create Class for provider
  2. Implement \smarteng\config\components\ConfigInterface
  3. Change in the configuration file on your provider

Usage

Db provider example

$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';

Uninstall

Applying migrations

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