zakharov-andrew / yii2-settings
Yii2 Settings
Installs: 259
Dependents: 0
Suggesters: 0
Security: 0
Stars: 3
Watchers: 1
Forks: 1
Open Issues: 0
Type:yii2-extension
Requires
- php: >=7.0
README
Yii2 settings with database module with GUI manager supported.
Installation
The preferred way to install this extension is through composer.
Either run
$ composer require zakharov-andrew/yii2-settings
or add
"zakharov-andrew/yii2-settings": "*"
to the require
section of your composer.json
file.
Subsequently, run
./yii migrate/up --migrationPath=@vendor/zakharov-andrew/yii2-settings/migrations
in order to create the settings table in your database.
Usage
There are 2 parts to this extension. A module and a component. The module provides a simple GUI to edit your settings. The component provides a way to retrieve and save settings programmatically.
Add this to your main configuration's modules array
'modules' => [
'settings' => [
'class' => 'ZakharovAndrew\settings\Module',
'bootstrapVersion' => 5, // if use bootstrap 5
],
// ...
],
Add this to your main configuration's components array
'components' => [
'settings' => [
'class' => 'ZakharovAndrew\settings\Settings',
],
],
Add a new rule for urlManager
of your application's configuration file, for example:
'urlManager' => [ 'rules' => [ 'settings' => 'settings/default/index', 'settings/create' => 'settings/default/create', 'settings/update' => 'settings/default/update', 'settings/delete' => 'settings/default/delete', 'setting-groups/create' => 'settings/setting-groups/create', 'setting-groups/update' => 'settings/setting-groups/update', 'setting-groups/delete' => 'settings/setting-groups/delete', ], ],
Typical component usage
$settings = Yii::$app->settings; $valueList = $settings->get('group1'); $value = $settings->get('group1', 'key'); $settings->set('group1', 'key', 'value'); // Automatically called on set(); $settings->clearCache();
License
yii2-settings it is available under a BSD 3-Clause License. Detailed information can be found in the LICENSE.md
.