PHP
  Home arrow PHP arrow Page 9 - Easy Application Configuration With pa...
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Moblin 
JMSL Numerical Library 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

Easy Application Configuration With patConfiguration
By: Vikram Vaswani, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2003-01-29

    Table of Contents:
  • Easy Application Configuration With patConfiguration
  • Plug And Play
  • Your Friendly Neighbourhood Spiderman
  • Anatomy Class
  • Version Control
  • The Write Stuff
  • Speaking Native
  • Not Your Type
  • When Time Is Money, Recycle!
  • Cache Cow
  • Link Zone

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Easy Application Configuration With patConfiguration - When Time Is Money, Recycle!


    (Page 9 of 11 )

    Here's another example, this one demonstrating how patConfiguration can be used in the context of a script accepting user input for application configuration. This script is divided into two parts: a form which displays the current configuration (if available) and allows the user to edit it, and a form processor, which accepts the new configuration and saves it to a file.

    In addition to patConfiguration, this script also uses the patTemplate engine for the actual interface generation - you can read more about patTemplate at http://www.devshed.com/Server_Side/PHP/patTemplate/

    Here's the template,

    <patTemplate:tmpl name="form"> <html> <head><basefont face="Arial"></head> <body> <h2>Configuration</h2> <table border="0" cellspacing="5" cellpadding="5"> <form action="configure.php" method="post"> <tr> <td>MySQL host name</td> <td><input type="text" name="db_host" value="{DB_HOST}"></td> </tr> <tr> <td>MySQL user name</td> <td><input type="text" name="db_user" value="{DB_USER}"></td> </tr> <tr> <td>MySQL user password</td> <td><input type="text" name="db_pass" value="{DB_PASS}"></td> </tr> <tr> <td colspan="2" align="center"><input type="submit" name="submit" value="Save Configuration"></td> </tr> </form> </table> </body> </html> </patTemplate:tmpl>
    and here's the script that does all the work:

    <? // include classes require("patConfiguration.php"); require("patTemplate.php"); // create patConfiguration object $conf = new patConfiguration; // set config file locations $conf->setConfigDir("config"); // create patTemplate object $template = new patTemplate; // set template location $template->setBasedir("templates"); // add templates to the template engine $template->readTemplatesFromFile("configuration.tmpl"); // form not yet submitted if (!$_POST["submit"]) { // check to see if config file exists if (file_exists("config/config.xml")) { // parse it and display configuration values $conf->parseConfigFile("config.xml"); $template->AddVar("form", "DB_HOST", $conf->getConfigValue("db.host")); $template->AddVar("form", "DB_USER", $conf->getConfigValue("db.user")); $template->AddVar("form", "DB_PASS", $conf->getConfigValue("db.pass")); } // parse and display the template $template->displayParsedTemplate("form"); } else { // accept the submitted values // and write them to a configuration file $conf->setConfigValue("db.host", $_POST['db_host']); $conf->setConfigValue("db.user", $_POST['db_user']); $conf->setConfigValue("db.pass", $_POST['db_pass']); $conf->writeConfigFile("config.xml", "xml", array("mode" => "pretty")); } ?>
    In this case, patConfiguration is used to read the application's database configuration from a file via the parseConfigFile() method and display the variable-value pairs contained within that file in an editable HTML form. The user may then modify these values and submit the form; patConfiguration will accept the new values and write them back to the configuration file via writeConfigFile().

    This kind of application configuration is pretty common to most Web-based tools - and patConfiguration lets you build an interface around it quickly and efficiently, with maximum code reuse and minimal time wastage.

    More PHP Articles
    More By Vikram Vaswani, (c) Melonfire


     

       

    PHP ARTICLES

    - Building a Content Management System with Co...
    - Filters and Login Systems for Web Applicatio...
    - Working with the Email Class in Code Igniter
    - Building Your Own System Tray Application Us...
    - Structuring Your Projects for Web Applicatio...
    - Inserting, Updating and Deleting Database Ro...
    - Building Your Own Desktop Notepad Applicatio...
    - Web Application Security Overview
    - Working with the Active Record Class in Code...
    - Generate PDF Documents with PHP on the Windo...
    - Sending Email with PHP Networking
    - Performing Strict Validation with the Code I...
    - The preg_replace_callback() function in PHP
    - PHP Networking
    - Validating Web Forms with the Code Igniter P...





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
    Stay green...Green IT