|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
rainco Smarty Rookie
Joined: 13 Oct 2003 Posts: 31 Location: Germany
|
Posted: Tue Nov 18, 2003 12:56 am Post subject: Multiple config-file directories |
|
|
Hi!
I wrote a patch for using multiple config-file directories by adding the following lines to function.config_load.php:
Code: |
} elseif (is_array($smarty->config_dir)) { // multiple config_dirs
if (preg_match("/^(.*):(.*)$/", $_file, $matches)) { // resource given
$_config_res = $matches[1]; // set config resource
$_file = $matches[2]; // set config file
if (@is_dir($smarty->config_dir[$_config_res])) { // resource is valid
$_config_dir = $smarty->config_dir[$_config_res]; // use custom resource
} else { // resource is not valid
$smarty->_syntax_error("config resource '".$_config_res."' is not valid",
E_USER_ERROR, __FILE__, __LINE__); // raise error
}
} else { // no resource given
if (@is_dir($smarty->config_dir['default'])) { // default resource valid
$_config_dir = $smarty->config_dir['default']; // use default resource
} else { // default resource not valid
$smarty->_syntax_error("default config_dir is not valid",
E_USER_ERROR, __FILE__, __LINE__); // raise error
}
}
|
This way it is possibe to use them in manner very much like templates resources. It is 100% downward compatible, but if you define $smarty->config_dir as an array you can access config_files through
Code: |
{config_load file="resource:file"}
|
or
Code: |
$smarty->config_load("resource:file");
|
$smarty->config_dir than should look something like this:
Code: |
$smarty->config_dir = array("default" => "configs", "resource" => "configs2", ...);
|
I would be very glad if this can find its way into the smarty distribution.
Thanks,
Rainer
PS: The patch follows.
Code: |
57a58,75
> } elseif (is_array($smarty->config_dir)) { // multiple config_dirs
> if (preg_match("/^(.*):(.*)$/", $_file, $matches)) { // resource given
> $_config_res = $matches[1]; // set config resource
> $_file = $matches[2]; // set config file
> if (@is_dir($smarty->config_dir[$_config_res])) { // resource is valid
> $_config_dir = $smarty->config_dir[$_config_res]; // use custom resource
> } else { // resource is not valid
> $smarty->_syntax_error("config resource '".$_config_res."' is not valid",
> E_USER_ERROR, __FILE__, __LINE__); // raise error
> }
> } else { // no resource given
> if (@is_dir($smarty->config_dir['default'])) { // default resource valid
> $_config_dir = $smarty->config_dir['default']; // use default resource
> } else { // default resource not valid
> $smarty->_syntax_error("default config_dir is not valid",
> E_USER_ERROR, __FILE__, __LINE__); // raise error
> }
> }
|
|
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Tue Nov 18, 2003 1:40 am Post subject: |
|
|
This is indeed nice!
Unfortunately, I must cast my vote as -1 to include this in the distribution -- I think a more general approach that is in-line with the template resource handler would be more appropriate.
In the meantime, this will likely help a few people out -- thanks, rainco! |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|