olessavluk / yii2-settings
Simple yii2 component for persistent settings storage
Installs: 65
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
Type:yii2-extension
pkg:composer/olessavluk/yii2-settings
Requires
- yiisoft/yii2: >=2.0.6
This package is not auto-updated.
Last update: 2025-12-21 01:09:40 UTC
README
Simple yii2 component for persistent settings storage
Installation:
The preferred way to install this extension is through composer.
Either run
php composer.phar require olessavluk/yii2-settings "*@dev"
or add
"olessavluk/yii2-settings": "*@dev"
to your composer.json file.
Usage
Add migration to create table for settings:
class m150929_124601_settings extends olessavluk\settings\m150929_122401_settings { }
Add the following code in your application configuration:
'components' => [ ... /** * required for advanced application template, * to share cache between frontend and backend */ 'frontCache' => [ 'class' => 'yii\caching\FileCache', 'cachePath' => '@frontend/runtime/cache', ], 'settings' => [ 'class' => '\olessavluk\settings\SettingsComponent', 'cacheName' => 'frontCache', 'defaults' => [ //optional default settings 'app' => [ 'siteName' => 'MyApp', 'adminEmail' => 'admin@exapmle.com', 'fromEmail' => 'no-reply@example.com', ], ], ], ... ]
Now you can use this component:
Yii->$app->settings->get('app', 'siteName'); Yii->$app->settings->delete('app', 'siteName'); Yii->$app->settings->set('app', 'siteName', 'NewSiteName');