shoxabbos/yii2-config

Yii2 config

Installs: 29

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 2

Forks: 0

Type:yii2-extension

1.0.0 2018-01-18 09:51 UTC

This package is not auto-updated.

Last update: 2024-04-28 03:36:01 UTC


README

Yii2 simple config

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist shoxabbos/yii2-config "*"

or add

"shoxabbos/yii2-config": "*"

to the require section of your composer.json file.

Demo

alt text

Usage

Once the extension is installed, simply use it in your code by :

Run migrations
./yii migrate  --migrationPath="@shoxabbos/config"
Controller map

For example: adding settings pages to admin module

'modules' => [
    'admin' => [
        'class' => 'app\modules\admin\Module',
        'controllerMap' => [
            'config' => 'shoxabbos\config\controllers\ConfigController'
        ]
    ],
]

After that, you can open the pages as:

/admin/config/create
/admin/config/update
/admin/config/view
/admin/config/index

Conponent

Register the package as a component

'components' => [
    'config' => [
        'class' => 'shoxabbos\config\Config',
    ],
]
Get config object
\Yii::$app->config->get('key');
Get config object property
\Yii::$app->config->get('key', 'propertyName');
Set cache duration
\Yii::$app->config->get('key', 'propertyName', 3600 * 24);
Set config
\Yii::$app->config->set('key', 'varchar 255', 'text');