$default_config_handler_func
提供一个回调函数,这个回调函数将在从资源里面无法获取到配置文件的时候调用。
Note
该设置一般在当配置文件是文件资源的时候起作用。 当找不到资源自身的时候,该设置不会调用,而是会抛出SmartyException异常。
Example 13.4. $default_config_handler_func
- <?php
- $smarty = new Smarty();
- $smarty->default_config_handler_func = 'my_default_config_handler_func';
- /**
- * 默认配置文件处理函数
- *
- * 当Smarty的文件资源无法载入需要的文件时调用。
- *
- * @param string $type 资源类型 (如: "file", "string", "eval", "resource")
- * @param string $name 资源名称 (如: "foo/bar.tpl")
- * @param string &$content 配置内容
- * @param integer &$modified 配置的修改时间
- * @param Smarty $smarty Smarty 实例
- * @return string|boolean 返回文件路径或布尔值,
- * 布尔值true表示$content 和 $modified已经赋值,
- * 布尔值false表示没有默认配置文件可供载入。
- */
- function my_default_config_handler_func($type, $name, &$content, &$modified, Smarty $smarty) {
- if (false) {
- // 返回文件路径
- return "/tmp/some/foobar.tpl";
- } elseif (false) {
- // 直接返回配置内容
- $content = 'someVar = "the config source"';
- $modified = time();
- return true;
- } else {
- // 告诉Smarty无法找到配置文件
- return false;
- }
- }
- ?>
原文: https://www.smarty.net/docs/zh_CN/variable.default.config.handler.func.tpl