PHP code example of sergey-lisitsyn / yii2-key-value-settings-storage

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

    

sergey-lisitsyn / yii2-key-value-settings-storage example snippets


    ......
    'controllerMap' => [
        'migrate' => [
            'class' => 'yii\console\controllers\MigrateController',
            'migrationNamespaces' => [
                ...
                'sergeylisitsyn\settingsStorage\migrations',
            ],
        ],
    ]
    ......

    ......
    'components' => [
        'settingsStorage' => [
            'class' => 'sergeylisitsyn\settingsStorage\SystemSetting',
            'storage' => 'sergeylisitsyn\settingsStorage\models\SettingStorage',
            'formatters' => [
                'string' => 'sergeylisitsyn\settingsStorage\models\formatters\StringStorageFormatter',
                'number' => 'sergeylisitsyn\settingsStorage\models\formatters\NumberStorageFormatter',
                'bool' => 'sergeylisitsyn\settingsStorage\models\formatters\BooleanStorageFormatter',
                'array' => 'sergeylisitsyn\settingsStorage\models\formatters\ArrayStorageFormatter'
            ],
        ],
    ]
    ......

    ......
    'modules' => [
        'settings-storage' => [
            'class' => 'sergeylisitsyn\settingsStorage\Module',
        ],
    ],
    ......

    $foo = Yii::$app->settingsStorage::create('foo', SystemSetting::TYPE_STRING, 'bar', 'xyz', 'test');
    $foo->save();
    // or just
    $saved = Yii::$app->settingsStorage->put('foo', SystemSetting::TYPE_STRING, 'bar', 'xyz', 'test');

    $fooVal = Yii::$app->settingsStorage->getValue('foo');
    echo($fooVal); // bar
    Yii::$app->settingsStorage->set('foo', 'baz');
    $fooVal = Yii::$app->settingsStorage->getValue('foo');
    echo($fooVal); // baz

    Yii::$app->settingsStorage->getValue('foo');

    Yii::$app->settingsStorage->set('foo', 'baz');

    Yii::$app->settingsStorage->setType('foo', SystemSetting::TYPE_NUMBER);
    Yii::$app->settingsStorage->set('foo', 1000000);

    $foo = Yii::$app->settingsStorage->get('foo');
    $foo->edit('foo', SystemSetting::TYPE_STRING, 'baz', 'zyx', 'another description');
    $foo->save();
    // or just
    Yii::$app->settingsStorage->update('foo', SystemSetting::TYPE_STRING, 'baz', 'zyx', 'another description');