Current location: Hot Scripts Forums » Programming Languages » PHP » Classes and config files


Classes and config files

Reply
  #1 (permalink)  
Old 04-02-04, 02:39 PM
therat's Avatar
therat therat is offline
Newbie Coder
 
Join Date: Jan 2004
Location: London
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Classes and config files

I have two files that each contain a class. I want to use the variables set in the config class in another class that is in a seperate file. I have tried various things but I can not get it to work. The 2 files are
PHP Code:

Config.php

<?php

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

    
// MySQL server name
    
$conf->mysqlserver 'localhost';

    
// MySQL database user
    
$conf->dbuser 'dbuser';

    
// MySQL database name
    
$conf->dbname 'dbname';

    
// MySQL database password
    
$conf->dbpwd 'dbpassword';

    
// 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->flagspath '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 $flagspath;
    }
    
?>
PHP Code:

Reports.php

<?

    
class Reports
    
{

    var 
$TSPC null// config class


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

     function 
country()
        {
            echo 
"<img src=\"".$this->TSPC->flagspath."/gb".$this->TSPC->imageextension."\">";
        }

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

        
//End the timer
        
function endTimer() {  
            
$mtime microtime (); 
            
$mtime explode (' '$mtime); 
            
$mtime $mtime[1] + $mtime[0]; 
            
$endtime $mtime
            
$totaltime round (($endtime $this->starttime), 5); 
            return 
$totaltime
        }
}
?>
How do I use the info from the config file in the main reports class. This is my first attempt at using a class.
Reply With Quote
  #2 (permalink)  
Old 04-04-04, 07:06 AM
Stefan's Avatar
Stefan Stefan is offline
Junior Code Guru
 
Join Date: Jun 2003
Location: Utrecht, The Netherlands
Posts: 599
Thanks: 0
Thanked 0 Times in 0 Posts
in the functions where you need the config information, you need to put

Code:
global $conf;
at the start of the function.
Reply With Quote
  #3 (permalink)  
Old 04-04-04, 09:41 AM
therat's Avatar
therat therat is offline
Newbie Coder
 
Join Date: Jan 2004
Location: London
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks, i'll give that a go.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump


All times are GMT -5. The time now is 10:22 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.