Cms Settings - rewritten for Yii 2

Installs: 70

Dependents: 0

Suggesters: 0

Security: 0

Stars: 2

Watchers: 2

Forks: 3


1.0.1 2016-06-15 23:02 UTC

This package is not auto-updated.

Last update: 2020-10-16 21:13:14 UTC


#Yii 2 Settings#



composer require "marsoltys/yii2-settings:*"

##Configuratoion## Add the component to the web.php config file components section:

'settings' => [
            'class'            => 'marsoltys\yii2-settings\CmsSettings',
            'cacheComponentId' => 'cache',
            'cacheId'          => 'global_website_settings',
            'cacheTime'        => 84000,
            'tableName'        => '{{settings}}',
            'dbComponentId'    => 'db',
            'createTable'      => **true**,
            'dbEngine'         => 'InnoDB',
'cache' => [
    'class' => 'yii\caching\FileCache', // Or any other type of Cache


* Set a database item:  
* $itemName can be an associative array() in key=>value pairs  ($itemValue="" in this case) 
Yii::$app->settings->set($categoryName, $itemName, $itemValue, $toDatabase=true);  
// Get a database item:  
Yii::$app->settings->get($categoryName, $itemName);  
// Get all items from a category:  
// Delete a database item:  
Yii::$app->settings->delete($categoryName, $itemName);  
// Delete all items from a category:  
//Import items from a file:  
$items=include('path/to/file.php');//returns an array() in key=>value pairs  
Yii::$app->settings->set($categoryName, $items);

The component uses something like "lazy loading" for loading items within a category, meaning that the items from a category will be loaded when you request them first time. Beside this, at the end of the request, the items from that requested category are written to cache, so next time when you request them, they will be served from cache.

Note, the component is smart enough to know itself when a new item/category has been added and refresh the cache accordingly so you don't have to keep track of the items you add to database.

Basically, in most of the cases, the database will be hit only once, then all items will be served from cache, which means you will get a nice way to manage the project configuration without performance penalties.