Re: [SMARTY] Hidden [.Section] config vars in php file
| From: | Tom Henry | Date: | Fri, 14 Mar 2003 18:15:50 +0000 |
| Subject: | Re: [SMARTY] Hidden [.Section] config vars in php file | ||
| References: | 1 2 3 4 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-8661@lists.php.net to get a copy of this message | ||
Sorry to be unclear - loading hidden conf vars into the .php file(s)
The approach I implemented from your recommendation - and which works 'as advertised' - thanks:
my.php
-------- this works -----
require_once(SMARTY_DIR."Config_File.class.php");
$conf = new Config_File($smarty->config_dir);
// == TJH === This _will_ get vars from [.Database]
$host = $conf->get('my.conf','Database','host'); // How 2 loop through all vars
$db = $conf->get('my.conf','Database','db'); // to eliminate hard-coding
$user = $conf->get('my.conf','Database','user'); // for each conf var
$pass = $conf->get('my.conf','Database','pass'); // as shown here
// these vars are now available here for use in db queries
// these vars are not 'assigned' - so are NOT visible in the .tpl files
-------
The refinement would be to somehow do an 'extract' on the "$conf" array/object so as to automagically get ALL the [.Database] .conf vars without having to know in advance what the var names are ( as would happen if someone added 'new' vars to the conf file.
Thanks for you patience with us newbies,
Tom
Monte Ohrt wrote:
Are you talking about loading config files in templates, or getting them directly in PHP? Please give an example. On Fri, 2003-03-14 at 09:29, Tom Henry wrote:Thanks Monte - this does the trick! As an additiopnal refinement - is there some way to do the equivalent of an 'extract()' - so that _all_ the hidden vars in the section are available -- thus alleviating the need to revist scripts if additions are made to the .conf files? Thanks for you kind and gentle help, Tom Henry Monte Ohrt wrote:You can set $config_read_hidden to true momentarily, but I like to use the Config_File class directly (see the FAQ in the wiki)