PHP Classes

File: simple_example.php

Recommend this page to a friend!
  Classes of Marko Tapio Manninen   Config Tool   simple_example.php   Download  
File: simple_example.php
Role: Example script
Content type: text/plain
Description: Example1 how to use class
Class: Config Tool
Read and write configuration text files
Author: By
Last change: Proper error reporting, uses safer get() method as an example.
Date: 19 years ago
Size: 1,167 bytes


Class file image Download
 * Configuration tool examples
 * @package ConfigTool
// Set notices off from error reporting if you want to use simpliest
// and straight method to get configuration variable names.
error_reporting( E_ALL ^ E_NOTICE );
// In development environment you should have:
// error_reporting( E_ALL );
* Include ConfigTool class and make object for the simple example
include( "../ConfigTool.php" );
// make object
$conf = new ConfigTool();
// to get configuration information from the text file
// any relative path can be used BUT absolute path must be used
// if you want to make changes and save new configuration files!
// see advanced_example to learn more
$conf->setConfigFromFile( "example_config_file.txt" );
// now it's up to you...
// print value of the key that you have defined on the configuration file
echo "hello1 = " . $conf->hello1;
// more safely: you can call get() method and give key name as a parameter
// to it and method will return undefined, if variable is not defined in
// conf object. This will prevent possible notice errors in your script.
echo "<br />myvar = " . $conf->get( 'myvar' );