lav45/yii2-project-configuration

This extension helps you to easily store and retrieve settings for your project.

Installs: 1 985

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 3

Forks: 1

Type:yii2-extension

1.0.2 2020-04-02 09:29 UTC

This package is auto-updated.

Last update: 2024-04-17 18:42:29 UTC


README

Latest Stable Version License Total Downloads

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()

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.