zakharov-andrew / yii2-settings
Yii2 Settings
Package info
github.com/ZakharovAndrew/yii2-settings
Type:yii2-extension
pkg:composer/zakharov-andrew/yii2-settings
Requires
- php: >=7.0
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
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();
👥 Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
📄 License
yii2-settings it is available under a BSD 3-Clause License. Detailed information can be found in the LICENSE.md.