PHP code example of yongtiger / yii2-setting

1. Go to this page and download the library: Download yongtiger/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/ */

    

yongtiger / yii2-setting example snippets


'modules' => [
    // ...
    'setting' => [
        'class' => 'yongtiger\setting\Module',
    ],
    // ...
],

'extensions/yongtiger/yii2-setting/*'

return [
    'components' => [
        'i18n' => [
            'translations' => [
                'extensions/yongtiger/yii2-setting/*' => [
                    'class' => 'yii\i18n\PhpMessageSource',
                    'sourceLanguage' => 'en-US',
                    'basePath' => '<your custumized message path>',    ///custumize your own translations
                    'fileMap' => [
                        'extensions/yongtiger/yii2-setting/setting' => 'settings.php',
                    ],
                ],
                // ...
            ],
        ],
        // ...
    ],
    // ...
];

$mySetting = \yongtiger\setting\Setting::get('site', 'name');

///Default value
$mySetting = \yongtiger\setting\Setting::get('not-exist-category', 'not-exist-name', 'default-value');
///Return 'default-value' if no exist setting category or key

$mySettingArray = \yongtiger\setting\Setting::setting;  ///get the current setting array

\yongtiger\setting\Setting::setting = $mySettingArray;  ///dynamically set a setting array

\yongtiger\setting\Setting::enableCaching = false;  ///disable caching
$mySetting = \yongtiger\setting\Setting::get('site', 'name');

http://<path-to>/index.php?r=setting/default/update&category=<category>

php composer.phar 

php yii migrate --migrationPath=@vendor/yongtiger/yii2-setting/src/migrations