PHP code example of rsol / yii2-settings

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

    

rsol / yii2-settings example snippets


./yii migrate/up --migrationPath=@vendor/rsol/yii2-settings/migrations

'modules' => [
    'settings' => [
        'class' => 'rsol\settings\Module',
        'sourceLanguage' => 'en'
    ],
    ...
],

'components' => [
    'settings' => [
        'class' => 'rsol\settings\components\Settings'
    ],
    ...
]


$settings = Yii::$app->settings;

$value = $settings->get('section.key');

$value = $settings->get('key', 'section');

$settings->set('section.key', 'value');

$settings->set('section.key', 'value', null, 'string');

$settings->set('key', 'value', 'section', 'integer');

// Automatically called on set();
$settings->clearCache();


class Site extends Model {
	public $siteName, $siteDescription;
	public function rules()
	{
		return [
			[['siteName', 'siteDescription'], 'string'],
		];
	}
	
	public function fields()
	{
	        return ['siteName', 'siteDescription'];
	}
	
	public function attributes()
	{
	        return ['siteName', 'siteDescription'];
	}
}

 $form = ActiveForm::begin(['id' => 'site-settings-form']); 

function actions(){
   return [
   		//....
            'site-settings' => [
                'class' => 'rsol\settings\SettingsAction',
                'modelClass' => 'app\models\Site',
                //'scenario' => 'site',	// Change if you want to re-use the model for multiple setting form.
                'viewName' => 'site-settings'	// The form we need to render
            ],
        //....
    ];
}

    public function actions()
    {
        return [
            'customer' => [
                'class' => SettingsAction::className(),
                'viewName' => 'custom'	// The form we need to render
                'config' => [
                    'attributes' => [
                        [
                            'section' => 'currency',
                            'key' => 'rur',
                            'label' => 'RUB currency',
                        ],
                        [
                            'section' => 'currency',
                            'key' => 'usd',
                            'label' => 'USD currency',
                        ],
                        [
                            'section' => 'system',
                            'key' => 'email',
                            'label' => 'System E-mail',
                        ],
                    ],
                    'rules' => [ // Additional rules for validation
                        [['currency.rur', 'currency.usd', 'system.email'], '

php composer.phar