nonameffh/yii2-setting

This package is abandoned and no longer maintained. No replacement package was suggested.

Store settings in the database. Forked from https://github.com/dinhtrung/yii2-setting

Installs: 561

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 2

Forks: 7

Type:yii2-extension

0.1.4 2018-07-04 10:31 UTC

This package is not auto-updated.

Last update: 2023-03-23 06:04:38 UTC


README

Store settings in the database

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist dinhtrung/yii2-setting "*"

or add

"dinhtrung/yii2-setting": "*"

to the require section of your composer.json file.

Usage

In your configuration file, add the setting component.

'components' => [
	...
	'setting' => 'dinhtrung\setting\Setting',
	...
]

You can choose which table to store the setting item, which will be auto-generate on demand.

'components' => [
	...
	'setting' => [
		'class' => 'dinhtrung\setting\Setting',
		'setting_table' => 'website_setting',
	]
	...
]

In anywhere from your code, you can use those features:

$setting = Yii::$app->setting->get('category', 'key', 'default value');
$setting = Yii::$app->setting->set('category', 'key', 'new value');

Or you can query all setting as one

$settingArray = Yii::$app->setting->get('category', 'key');
$settingArray = Yii::$app->setting->get('category', 'key', 'default value');
$settingArray = Yii::$app->setting->set('category', [
	'key1' => 'value1',
	'key2' => 'value2',
	'key3' => 'value3',
]);