yii2-project-configuration
, (*1)
This extension helps you to easily store and retrieve settings for your project., (*2)
Installation
The preferred way to install this extension through composer., (*3)
You can set the console, (*4)
~$ composer require "lav45/yii2-project-configuration" --prefer-dist
or add, (*5)
"require": {
"lav45/yii2-project-configuration": "1.0.*"
}
in require
section in composer.json
file., (*6)
Using
// Yii::setAlias('@app_config_path', __DIR__ . '/settings');
$db_name = config('db_name', 'site-db-name');
$db_host = config('db_host', 'localhost');
return [
'components' => [
'db' => [
'class' => 'yii\db\Connection',
'dsn' => "mysql:host={$db_host};dbname={$db_name}",
'username' => config('db_username', 'root'),
'password' => config('db_password', '****'),
'enableSchemaCache' => true,
'charset' => 'utf8',
],
]
];
Management
Control is made through a console controller
Will add it to the console application's configuration file, (*7)
return [
'controllerMap' => [
'config' => 'lav45\projectConfiguration\console\controllers\ConfigController'
]
];
Use console controller
# Set value by key
~$ yii config db_name site-db
# Display all keys
~$ yii config
~> db_name: site-db
# Show value by key
~$ yii config db_name
~> site-db
# Delete key
~$ yii config/delete db_name
You can configure the component using Yii::setAlias() before using the config()
, (*8)
Key |
Default value |
Description |
@app_config_key |
'app-config' |
The key which will be stored settings |
@app_config_path |
'/storage' |
Path where will be stored the file with the settings |
License
yii2-project-configuration it is available under a BSD 3-Clause License. Detailed information can be found in the LICENSE.md
., (*9)