Re: [SMARTY] Multiple Config Directories

From: Date: Thu, 13 Mar 2003 14:17:34 +0000
Subject: Re: [SMARTY] Multiple Config Directories
References: 1 2  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-8619@lists.php.net to get a copy of this message
Just so you know, you don't need to reset an array before you loop through it in a foreach. You only need to reset it before a while loop. ~Paul Hinrich Donner wrote:
On Monday 10 March 2003 11:07, Hinrich Donner wrote:
I need access to multiple directories like $smarty->plugins_dir.
Hi, I have implemented something simple that enables multiple configuration directories. At the moment I do not know if there are side effects. I create a class with constructor derived from Smarty. I implemented the following method:
    /**
     * Config Load
     *
     * This method overwrite the original Smarty method.  It enables the use
     * of multiple configuration files.  The directories are processed in
     * order they are stored in the array.
     *
     * @param string $file The file name located in one of the directories
     * @param string $section The section in the configuration file
     * @param string $scope The scope for the variables
     * @see Smarty::config_load()
     * @todo Look for side effects with Smarty.
     */
    function config_load($file, $section = null, $scope = 'global')
    {
        // If we do not have an array, we can proceed the normal method.
        //
        if (!isset($this->config_dirs) || !is_array($this->config_dirs))
            return parent::config_load(&$file, &$section, &$scope);
        // Now we have to move through the directories.
        //
        reset($this->config_dirs);
        foreach ($this->config_dirs as $config_dir)
        {
            $this->config_dir = $config_dir;
            parent::config_load(&$file, &$section, &$scope);
        }
    }
To define the directories use (mind the last 's') $smarty->config_dirs = array('foo/', 'bar/'); In this case, the variable $smarty->config_dir wil NOT be processed! Hinrich
-- Paul Lockaby paul@paullockaby.com http://www.paullockaby.com

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