Page 1 of 1

Config files and classes

Posted: Wed Mar 31, 2004 3:26 pm
by therat
I have 2 files as below. The first is a general config file that holds variables used throughout. The second is a class that will eventually create some reports. How do I call the config class inside the reprts class. I hope this makes sense, it's the first time I have tried to use classes.
Config.php

Code: Select all

<?php

	//create new config class
	$conf = new Config();

	// MySQL server name
	$conf->mysqlserver = 'localhost';
	// MySQL database user
	$conf->dbuser = 'username';
	// MySQL database name
	$conf->dbname = 'databasename';
	// MySQL database password
	$conf->dbpwd = 'password';
	// show flag of visitor
	// option are: 1 show flags, 0 do not show flags
	$conf->countryflags = 1;
	// flag extension
	$conf->imageextension = '.png';
	// flag directory
	$conf->countryflagspath = 'images/flags';

	class Config
	{
		// MySQL server name
		var $mysqlserver;
		// MySQL database user
		var $dbuser;
		// MySQL database name
		var $dbname;
		// MySQL database password
		var $userpwd;
		// show flag of visitor
		var $countryflags;
		// flag extension
		var $imageextension;
		// flag directory
		var $countryflagspath;
	}
	
?>
Reports.php

Code: Select all

<?

    class Reports
    {

    function Reports()
        {
            $this->startTimer();
        }
        

     function country()
        {
            echo "<img src='gb.png'>";
        }

		function startTimer() 
		{ //function to start the timer. 
			$mtime = microtime (); 
			$mtime = explode (' ', $mtime); 
			$mtime = $mtime[1] + $mtime[0]; 
			$this->starttime = $mtime; 
		} 

		function endTimer() 
		{ //function to end the timer. 
			$mtime = microtime (); 
			$mtime = explode (' ', $mtime); 
			$mtime = $mtime[1] + $mtime[0]; 
			$endtime = $mtime; 
			$totaltime = round (($endtime - $this->starttime), 5); 
			return $totaltime; 
		}
}
?>

Posted: Wed Mar 31, 2004 4:43 pm
by kettle_drum
Make a class constructor for the config class that does the following:

Code: Select all

// MySQL server name 
   $this->mysqlserver = 'localhost'; 
   // MySQL database user 
   $this->dbuser = 'username'; 
   // MySQL database name 
   $this->dbname = 'databasename'; 
   // MySQL database password 
   $this->dbpwd = 'password'; 
   // show flag of visitor 
   // option are: 1 show flags, 0 do not show flags 
   $this->countryflags = 1; 
   // flag extension 
   $this->imageextension = '.png'; 
   // flag directory 
   $this->countryflagspath = 'images/flags';
Then just call the class from inside the other class.

Posted: Thu Apr 01, 2004 12:34 pm
by therat
Thanks, i'll try that later

Posted: Thu Apr 01, 2004 2:27 pm
by therat
kettle_drum wrote:Make a class constructor for the config class that does the following:

Code: Select all

// MySQL server name 
   $this->mysqlserver = 'localhost'; 
   // MySQL database user 
   $this->dbuser = 'username'; 
   // MySQL database name 
   $this->dbname = 'databasename'; 
   // MySQL database password 
   $this->dbpwd = 'password'; 
   // show flag of visitor 
   // option are: 1 show flags, 0 do not show flags 
   $this->countryflags = 1; 
   // flag extension 
   $this->imageextension = '.png'; 
   // flag directory 
   $this->countryflagspath = 'images/flags';
Then just call the class from inside the other class.
I am doing something wrong because I cannot get this to work. Does the above get added to the actual class code already in config.php, or should it replace the top part of that file. Also, how do I call the class inside the reports.php file. I have always used includes up to now so this is a bit strange still.