myconfig This component allows you to manage your website various config items via database or files.

  1. Important Note
  2. Requirements
  3. Usage

This component allows you to manage your website various config items via database or files. In my case, i created this component because my projects require an area in the admin panel where the clients can set various config items for the website(Website keywords/description | admin theme | website theme | maintenance theme | contact emails | etc) and i also have some classes that needs to have their params set dynamically from the admin panel.

Basically, you can save your custom config to database, you can load custom config items from filesdatabase and you can cache them if you like.

Important Note

You should use my other extension( http://www.yiiframework.com/extension/settings/ ) as it proven to be more reliable and flexible than this one.

Requirements

Yii 1.1 (tested on 1.1.5)

Usage

In your main.php file, make sure that in the components area, you have something like:

'components'=>array(
[...]
        'cfg'=>array(
            'class' =>  'application.components.MyConfig',
            'cacheId'=>null,
            'useCache'=>false,
            'cacheTime'=>0,
            'tableName'=>'',
            'createTable'=>false,
            'loadDbItems'=>false,
            'serializeValues'=>true,
            'configFile'=>'',
        ),
[...]

In the archive you will find a README file which explains detailed how to use this class.

However, this is a short introduction in the methods available:

AVAILABLE METHODS:
1) public function setItem($key, $value='')
$key can be a string or an associative array ('key'=>'value');
Saves an item in memory during runtime.

2) public function setDbItem($key, $value='')
It saves the item in database, then calls setItem() to make the item available

3) public function getItem($key)
Retrieves an item. Note that the retrieved item can be a string or array or even object so you need to do additional checks yourself.

4) public function deleteItem($key)
$key can be a string or an array of keys to be removed
Remove item

5) public function deleteDbItem($key)
$key can be a string or an array of keys to be removed
Removes items from database, then calls deleteItem()

6) public function deleteItems()
Removes all items

7) public function deleteDbItems()
Removes all the items from database, then calls deleteItems();

8) public function loadDbItems()
Loads the items from database during runtime, and it saves them to cache it it's the case.
Note, that if the 'loadDbItems' property is set to true, the items are loaded at init, so you don't have to do it manually.

9)public function loadConfigFile($fileArray,$keyName=null)
$fileArray can be a string or an associative array('keyName'=>'fileName');
It will load a config file and make it's contents available via getItem('keyName');
The file needs to return an associative array.

10)public function toArray()
Returns all the stored items

11)public function fromConfigToDb($fileName, $fileKey='')
Almost the same behaviour as loadConfigFile() only it saves the items to database and then calls setDbItem();

Have fun using it as for me it proven to be a life saver component. The methods within the class are documented and also are presented in the README file, but if you have any questions, just let me know.

Also, any feedback is highly appreciated.

8 1
14 followers
1 093 downloads
Yii Version: 1.1
License: (not set)
Category: Others
Developed by: twisted1919
Created on: Jan 14, 2011
Last updated: 12 years ago

Downloads

show all

Related Extensions