Re: [SMARTY] Re: Accessing config vars in PHP.

From: Date: Tue, 01 Oct 2002 21:22:41 +0000
Subject: Re: [SMARTY] Re: Accessing config vars in PHP.
References: 1 2  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-6060@lists.php.net to get a copy of this message
Hi, Wednesday, October 2, 2002, 1:07:29 AM, you wrote: PL> Michal Zajaczkowski wrote: >> Is there a way of accessing assigned config vars in the PHP script? >> I have done it by $smarty->configs[0][varname], but it's not quite >> correct, since the "configs" array is a "private" var of the Smarty >> class. >> Is there any correct way of doing that? PL> This was asked forever ago, and I didn't find an answer, so I figured PL> I'd post the code that I used to accomplish just that. It's kinda rough PL> around the edges, but it works, just as long as you don't have any PL> comments in your config file. PL> $conf = "/www/sitename/templates/dostuff.conf"; PL> if ($fp = @fopen($conf, "r")) { PL> while ($line = @fgets($fp, 1024)) { PL> list ($name, $value) = explode ("=", $line); PL> $name = trim($name); PL> $value = trim($value); PL> define($name,$value); PL> } PL> } else { PL> echo "<BR>Could not find config file."; PL> exit; PL> } PL> Easy enough, eh? Yes you can use the Config_File class directly. $conf = new Config_File; // change yes|true|on and no|false|off to boolean values $conf->boolean = true; // overwrite same named vars, or accumulate array $conf->overwrite = true; // get global vars $foo = $conf->get('english.conf'); // get one global var $foo = $conf->get('english.conf',null,'var_name'); // get var from section $foo = $conf->get('english.conf','section_name','var_name'); Daniil

« previous php.smarty.general (#6060) next »