razonyang/yii2-setting

Yii2 Setting Manager

Installs: 3 994

Dependents: 1

Suggesters: 0

Security: 0

Stars: 5

Watchers: 3

Forks: 0

Open Issues: 0

Type:yii2-extension

1.0.0 2019-08-21 04:56 UTC

This package is auto-updated.

Last update: 2024-11-21 21:04:19 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();