Skip to content
Yii Settings Extension
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
tests
.gitignore
.scrutinizer.yml
.travis.yml
CHANGELOG.md
README.md
composer.json
phpunit.xml

README.md

Yii Settings Extension

This extension provides support for persistent settings for Yii2.

Build Status Scrutinizer Code Quality Code Coverage Total Downloads Latest Stable Version

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist solutosoft/yii-settings

or add

"solutosoft/yii-settings": "*"

Configuration

To use the Setting Component, you need to configure the components array in your application configuration:

'components' => [
    'settings' => [
        'class' => 'Soluto\Settings\Settings',
    ],
],

Usage:

$settings = Yii::$app->settings;

$settings->set('key');

$settings->set('section.key');

// Checking existence of setting
$settings->exists('key');

// Removes a setting
$settings->remove('key');

// Removes all settings
$settings->remove();

Events

You can use beforeExecute event to store extra values and apply extra conditions on command execution

<?php

'components' => [
    'settings' => [
        'class' => 'Soluto\Settings\Settings',
        'on beforeExecute' => function ($event) {
            $event->data = ['user_id' => Yii::$app->user->id];
        }
    ],
],

$settings = Yii::$app->settings;

//INSERT (`key`,`value`, `user_id`) INTO `setting` VALUES ('website', 'http://example.org', 1)
$settings->set('website', 'http://example.org');

//SELECT `value` FROM `setting` WHER (`settings`.`key` = 'website' and `settings`.`user_id` = 1)
$settings->get('website', 'http://example.org');
You can’t perform that action at this time.