Class yeesoft\components\Settings

Inheritanceyeesoft\components\Settings » yii\base\Component

This component allows you to get and set settings from application.

Usage examples:

Set setting: ~~~ Yii::$app->settings->set(['general','title'],'Yee Site'); ~~~

Get setting: ~~~ $setting = Yii::$app->settings->get('general.title'); ~~~

Public Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
$cache \yii\caching\Cache|string The cache object or the application component ID of the cache object. yeesoft\components\Settings
$cacheKey string Cache key yeesoft\components\Settings
$modelClass string Setting model. yeesoft\components\Settings

Public Methods

Hide inherited methods

MethodDescriptionDefined By
explodeKey() Explode setting key. yeesoft\components\Settings
get() Get setting value for the given key and group. yeesoft\components\Settings
getFromDB() Get setting value from datebase for the given key and group. yeesoft\components\Settings
init() Initialize the component yeesoft\components\Settings
set() Set setting value for the given key and group or create new setting field if it not exists. yeesoft\components\Settings

Protected Methods

Hide inherited methods

MethodDescriptionDefined By
load() Load setting from cache or from database if not found in cache. yeesoft\components\Settings

Property Details

$cache public property

The cache object or the application component ID of the cache object. Settings will be cached through this cache object, if it is available.

Set this property to null if you do not want to cache the settings.

public \yii\caching\Cache|string $cache 'cache'
$cacheKey public property

Cache key

public string $cacheKey 'settings'
$modelClass public property

Setting model. Make sure your settings model calls clearCache in the afterSave callback

public string $modelClass 'yeesoft\models\Setting'

Method Details

explodeKey() public static method

Explode setting key.

public static void explodeKey ( $key )
$key \yeesoft\components\type
throws \yii\base\InvalidParamException
get() public method

Get setting value for the given key and group.

You can use dot notation to separate the group from the key: ~~~ $value = $settings->get('group.key'); ~~~

or array: ~~~ $value = $settings->get(['group', 'key']); ~~~

public mixed get ( $key, $default NULL, $language NULL )
$key array|string
$default null

Default value

$language
getFromDB() public method

Get setting value from datebase for the given key and group.

public mixed getFromDB ( $group, $key, $language NULL, $default NULL )
$group \yeesoft\components\type

Setting group

$key \yeesoft\components\type

Setting key

$language
$default \yeesoft\components\type

Default value

init() public method

Initialize the component

public void init ( )
throws \yii\base\InvalidConfigException
load() protected method

Load setting from cache or from database if not found in cache.

protected void load ( $group, $key, $language NULL )
$group string

Setting group

$key string

Setting key

$language
set() public method

Set setting value for the given key and group or create new setting field if it not exists.

You can use dot notation to separate the group from the key: ~~~ $value = $settings->get('group.key'); ~~~

or array: ~~~ $value = $settings->get(['group', 'key']); ~~~

public boolean set ( $key, $value, $description NULL )
$key
  • setting key
$value
  • setting new value
$description
  • description field in order of creating new setting field