Smarty 图标

您可以根据商标声明使用 Smarty 徽标。

Smarty Template Engine Smarty Template Engine

如需赞助、广告、新闻或其他查询,请联系我们:

使用 Smarty 的网站

广告

$default_config_handler_func

当无法从资源获取配置文件时,将调用此函数。

注意

目前的默认处理程序仅针对文件资源。当无法找到资源本身时不会触发该处理程序,此时将抛出 SmartyException。

示例 13.4 $default_config_handler_func

<?php

$smarty = new Smarty();
$smarty->default_config_handler_func = 'my_default_config_handler_func';

/**
 * Default Config Handler
 *
 * called when Smarty's file: resource is unable to load a requested file
 * 
 * @param string   $type     resource type (e.g. "file", "string", "eval", "resource")
 * @param string   $name     resource name (e.g. "foo/bar.tpl")
 * @param string  &$content  config's content
 * @param integer &$modified config's modification time
 * @param Smarty   $smarty   Smarty instance
 * @return string|boolean   path to file or boolean true if $content and $modified 
 *                          have been filled, boolean false if no default config 
 *                          could be loaded
 */
function my_default_config_handler_func($type, $name, &$content, &$modified, Smarty $smarty) {
    if (false) {
        // return corrected filepath
        return "/tmp/some/foobar.tpl";
    } elseif (false) {
        // return a config directly
        $content = 'someVar = "the config source"';
        $modified = time();
        return true;
    } else {
        // tell smarty that we failed
        return false;
    }
}

?>