Yii2 Setting Manager

Yii2 Setting Manager

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();

发表评论

电子邮件地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据