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');
}
}
}