razonyang/yii2-setting

Yii2 设置管理器

安装次数: 3,994

依赖关系: 1

建议者: 0

安全性: 0

星标: 5

关注者: 3

分支: 0

开放性问题: 0

类型:yii2-extension

1.0.0 2019-08-21 04:56 UTC

This package is auto-updated.

Last update: 2024-09-21 20:36:09 UTC


README

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

安装

composer require razonyang/yii2-setting

使用

配置

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}}',
        ],
    ],
];

迁移

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