PHP code example of razonyang / yii2-setting

1. Go to this page and download the library: Download razonyang/yii2-setting library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

razonyang / yii2-setting example snippets


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

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