Smarty成員變量:$default_config_handler_func

2018-10-19 15:38 更新

$default_config_handler_func

提供一個回調函數,這個回調函數將在從資源里面無法獲取到配置文件的時候調用。

溫馨提示:

該設置一般在當配置文件是文件資源的時候起作用。 當找不到資源自身的時候,該設置不會調用,而是會拋出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;
    }
}

?>

以上內容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號