PHP code example of jlorente / yii2-config-variables

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

    

jlorente / yii2-config-variables example snippets


class mXXXXXX_XXXXXX_a_simple_configuration_variable_creation extends Migration {

    /**
     * @inheritdoc
     */
    public function up() {
        $v = new Variable([
            'code' => 'CODE-OF-MY-CONFIGURATION-VARIABLE',
            'name' => 'A simply boolean configuration variable',
            'type' => Variable::TYPE_BOOLEAN,
            'value' => true
        ]);
        if ($v->save() === false) {
            throw new Exception('Unable to save the configuration variable');
        }
    }
}

class mXXXXXX_XXXXXX_a_type_object_variable_creation extends Migration {

    /**
     * @inheritdoc
     */
    public function up() {
        $v = new Variable([
            'code' => 'CODE-OF-MY-TYPE_OBJECT-VARIABLE',
            'name' => 'Posts Ranking weights',
            'type' => Variable::TYPE_OBJECT,
            'value' => [
                'postsNumber' => 40,
                'postsValoration' => 40,
                'commentsNumber' => 20
            ]
        ]);
        if ($v->save() === false) {
            throw new Exception('Unable to save the configuration variable');
        }
    }
}

    // ... other configurations ...
    "modules" => [
        // ... other modules ...
        "config" => [
            "class" => "jlorente\config\Module"
        ]
    ]

    // ... other configurations ...
    "modules" => [
        // ... other modules ...
        "config" => [
            "class" => "jlorente\config\Module",
            "messageConfig" => [
                "basePath" => "PATH-TO-MY-TRANSLATION",
            ]
        ]
    ]

    // ... other configurations ...
    "modules" => [
        // ... other modules ...
        "config" => [
            "class" => "jlorente\config\Module",
            "layout" => "PATH-TO-MY-LAYOUT"
        ]
    ]

    $value = Variable::value('CODE-OF-MY-CONFIGURATION-VARIABLE');

    $value = Variable::value('CODE-OF-MY-TYPE_OBJECT-VARIABLE');
    echo $value->postsNumber;
    echo $value->postsValoration;
    echo $value->commentsNumber;

    Variable::set('CODE-OF-MY-CONFIGURATION-VARIABLE', 115);

    // ... other configurations ...
    "bootstrap" => [
        // ... other module ids ...
        , "config"
    ],
bash
$ php composer.phar