lav45 / yii2-project-configuration
This extension helps you to easily store and retrieve settings for your project.
Installs: 3 674
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 3
Forks: 1
Type:yii2-extension
Requires
- ext-json: *
- lav45/yii2-settings: >=1.2.3
- yiisoft/yii2: 2.0.*
Requires (Dev)
- roave/security-advisories: dev-master
This package is auto-updated.
Last update: 2024-10-17 19:54:12 UTC
README
This extension helps you to easily store and retrieve settings for your project.
Installation
The preferred way to install this extension through composer.
You can set the console
~$ composer require "lav45/yii2-project-configuration" --prefer-dist
or add
"require": {
"lav45/yii2-project-configuration": "1.0.*"
}
in require
section in composer.json
file.
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
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()
License
yii2-project-configuration it is available under a BSD 3-Clause License. Detailed information can be found in the LICENSE.md
.