Your IP : 216.73.216.40


Current Path : /var/www/html/ajay/phpwebsite-1.8.x/docs/
Upload File :
Current File : /var/www/html/ajay/phpwebsite-1.8.x/docs/Settings_Class.txt

Setting Class
by Matthew McNaney
---------------------------------------------------------

Introduction
------------
The settings class is a basic mechanism for storing system
variables. It prevents having to make a single row table for each
module you develop which just contains your module's settings.


Installation
------------
The PHPWS_Settings class requires one thing: a settings.php
file. Create the file under the directory:

mod/your_module/inc/

This is the file the class will check if no settings have been made
yet. Think of it as a defaults file.

The file should look like so:

<?php

$settings = array('name_of_setting' => 'value_of_default_setting');

?>


Add additional settings to the array as you see fit.


Getting a setting
-----------------
Simply call

$result = PHPWS_Settings::get('module_name', 'name_of_setting');

In this case, $result would be 'value_of_default_setting'.

You may also get all the current settings in an array by leaving out
the name of the setting:

$result = PHPWS_Settings::get('module_name');

The $result would be:

array ['name_of_setting'] => 'value_of_default_setting';



Setting a value
----------------
Once you start setting values (and saving them), the new values will
overwrite the default values.

Setting them is as easy as getting them:

PHPWS_Settings::set('module_name', 'name_of_setting', 'new_value');

The new settings will not be permanent until you save them however:

PHPWS_Settings::save('module_name');

Now if we run get again:

$result = PHPWS_Settings::get('module_name', 'name_of_setting');

the result would be 'new_value'.


Final notes
----------------
You can store almost any value though I would NOT recommend storing an
object.

If you store an array or object, you will need to serialize it when
you set it and unserialize when retrieving it.

Conclusion
----------------
That's all folks!