NoPic eZine
  
Home
Impressum/Imprint
Datenschutz/Policies
 
1.Issue 2006.06/1
 1.1.phpWebSite 1.0.0RC1 released
 1.2.Installing pWS 1.0.0rc1
 1.3.Running thru install
 1.4.First anonymous touch
 1.5.Exploring fallout surface inside
 1.6.Module substitution
 1.7.Directory Tree
 1.8.Database Tables
 1.9.ReadMe summary
   Access.txt
   bbcode.txt
   Cache_Lite.txt
   Categories.txt
   Clipboard.txt
   ControlPanel.txt
   Converting_Modules.txt
   Cookie.txt
   CREDITS.txt
   Database_Class.txt
   DB_Pager.txt
   Demographics.txt
   devdoc.modlayout.txt
   Developer_Rules.txt
   Editor.txt
   Forms.txt
   INSTALL.doc.txt
   Key.txt
   Known_Errors.txt
   Language.txt
   LICENSE.txt
   MiniAdmin.txt
   Mod_Rewrite.txt
   Module_Development.txt
   My_Page.txt
   README.doc.txt
   README.txt
   Related.txt
   Search.txt
   Settings_Class.txt
   SmartTags.txt
   Style_Format.txt
   template.txt
   Theme_Creation.txt
   Using_Javascript.txt
   Version.txt
   WYSIWYG.txt
 1.10.Using module WebPages
 1.11.Using module MenuManager
 1.12.Using webPages Editor
 1.13.Styling and Themes

    en

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/conf/

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 are storing an array, you have the option to append to a
setting.
For example,

$color_list = array ('orange', 'blue', 'red');

foreach ($color_list as $color) {
    PHPWS_Settings::append('my_mod', 'colors', $color);
}

Be warned that if you try to append a setting that is not empty or not
already an array, append will fail and return FALSE.


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

    en

Copyright © 2006, VbID Verlagsbüro GmbH
pWS modules dcP, dcT, dc4db, Copyright © 2006, VbID Verlagsbüro GmbH
This Site is powered by phpWebSite © The Web Technology Group, Appalachian State University