Get Smarty

Donate

Smarty Icon

You may use the Smarty logo according to the trademark notice.

Smarty Template Engine Smarty Template Engine

For sponsorship, advertising, news or other inquiries, contact us at:

Sites Using Smarty

Buy cheap glasses from Cheapglasses123.com and save up to 80%.

Where to buy prescription glasses? EyewearCanada.com is your best choice!

Where to buy discount wedding dresses and cheap smart dresses free shipping - Weddingdresstrend.com

Shop for 2018 World Cup Football Boots Online sale at guthjcc.com

Browse best 2018 world cup soccer cleats and shoes from SoccerAzteca.com

Advertisement

$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;
    }
}

?>

  

Comments
No comments for this page.
Post a Comment
All comments are moderated. Support questions are ignored, use the forums instead.
Author:
Email: (not shown)
What is 12 plus 19? (Are you human?)

Advertisement