razonyang/yii2-setting

Yii2 Setting Manager

Installs: 2 534

Dependents: 1

Suggesters: 0

Stars: 3

Watchers: 1

Forks: 0

Open Issues: 0

Type:yii2-extension

1.0.0 2019-08-21 04:56 UTC

README

Build Status Scrutinizer Code Quality Code Coverage Latest Stable Version Total Downloads LICENSE

Installation

composer require razonyang/yii2-setting

Usage

Configuration:

return [
    // console
    'controllerMap' => [
        'migrate' => [
            'migrationNamespaces' => [
                'RazonYang\Yii2\Setting\Migration',
            ],
        ],
    ],

    'components' => [
        // common
        'settingManager' => [
            'class' => \RazonYang\Yii2\Setting\DbManager::class,
            'enableCache' => YII_DEBUG ? false : true,
            'cache' => 'cache',
            'mutex' => 'mutex',
            'duration' => 600,
            'db' => 'db',
            'settingTable' => '{{%setting}}',
        ],
    ],
];

Migration:

$ yii migrate
$settingManager = Yii::$app->get('settingManager');

// fetch by ID
$value = $settingManager->get($id, $defaultValue); // defaultValue is optional

// fetchs all settings
$settings = $settingManager->getAll();

// flush cache
$settingManager->flushCache();