Smarty::addConfigDir PHP Method

addConfigDir() public method

Add config directory(s)
public addConfigDir ( string | array $config_dir, $key = null ) : Smarty
$config_dir string | array directory(s) of config sources
return Smarty current Smarty instance for chaining
    public function addConfigDir($config_dir, $key = null)
    {
        // make sure we're dealing with an array
        $this->config_dir = (array) $this->config_dir;
        if (is_array($config_dir)) {
            foreach ($config_dir as $k => $v) {
                $v = str_replace(array('//', '\\\\'), DS, rtrim($v, '/\\')) . DS;
                if (is_int($k)) {
                    // indexes are not merged but appended
                    $this->config_dir[] = $v;
                } else {
                    // string indexes are overridden
                    $this->config_dir[$k] = $v;
                }
            }
        } else {
            $v = str_replace(array('//', '\\\\'), DS, rtrim($config_dir, '/\\')) . DS;
            if ($key !== null) {
                // override directory at specified index
                $this->config_dir[$key] = rtrim($v, '/\\') . DS;
            } else {
                // append new directory
                $this->config_dir[] = rtrim($v, '/\\') . DS;
            }
        }
        $this->joined_config_dir = join(DIRECTORY_SEPARATOR, $this->config_dir);
        return $this;
    }

Usage Example

Example #1
0
 /**
  * Get the evaluated contents of the view at the given path.
  *
  * @param string $path
  * @param array $data
  * @return string
  */
 protected function evaluatePath($__path, $__data)
 {
     $configKey = 'smarty::';
     $caching = $this->config[$configKey . 'caching'];
     $cache_lifetime = $this->config[$configKey . 'cache_lifetime'];
     $debugging = $this->config[$configKey . 'debugging'];
     $left_delimiter = $this->config[$configKey . 'left_delimiter'];
     $right_delimiter = $this->config[$configKey . 'right_delimiter'];
     $template_path = $this->config[$configKey . 'template_path'];
     $compile_path = $this->config[$configKey . 'compile_path'];
     $cache_path = $this->config[$configKey . 'cache_path'];
     // Get the plugins path from the configuration
     $plugins_paths = $this->config[$configKey . 'plugins_paths'];
     // 取得config path为了fis map.json
     $configs_paths = $this->config[$configKey . 'configs_paths'];
     // Create smarty object.
     $smarty = new \Smarty();
     $smarty->setTemplateDir($template_path);
     $smarty->setCompileDir($compile_path);
     $smarty->setCacheDir($cache_path);
     // Add the plugin folder from the config to the Smarty object.
     // Note that I am using addPluginsDir here rather than setPluginsDir
     // because I want to add a secondary folder, not replace the
     // existing folder.
     foreach ($plugins_paths as $path) {
         $smarty->addPluginsDir($path);
     }
     foreach ($configs_paths as $path) {
         $smarty->addConfigDir($path);
     }
     $smarty->debugging = $debugging;
     $smarty->caching = $caching;
     $smarty->cache_lifetime = $cache_lifetime;
     $smarty->compile_check = true;
     $smarty->left_delimiter = $left_delimiter;
     $smarty->right_delimiter = $right_delimiter;
     // $smarty->escape_html = true;
     $smarty->error_reporting = E_ALL & ~E_NOTICE;
     foreach ($__data as $var => $val) {
         $smarty->assign($var, $val);
     }
     return $smarty->fetch($__path);
 }