Skip to content

A Yii2 Component to store common setting in the database.

Notifications You must be signed in to change notification settings

tomaszkane/yii2-setting

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 

Repository files navigation

Yii2 Setting Component

Store settings in the database

Installation

The preferred way to install this extension is through composer.

Either run

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

or add

"tomaszkane/yii2-setting": "*"

to the require section of your composer.json file.

Usage

In your configuration file, add the setting component.

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

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

'components' => [
	...
	'setting' => [
		'class' => 'tomaszkane\setting\Setting',
		'settingTable' => 'website_setting',
	]
	...
]

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

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

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',
]);
Yii::$app->setting->commit();

About

A Yii2 Component to store common setting in the database.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 100.0%