Smarty中的变量、方法(一)

require('./include.php');

$xpx = 100;

//分配变量(a,b),a为模板中的变量名,b为值
//[xpx] = 100
$smarty->assign('xpx',$xpx);
//    [ypx] => Array
//        (
//            [app] => local
//            [host] => post
//        )
$smarty->assign('ypx',array('app' => 'local', 'host' => 'post'));

//分配变量到模板
//(a,b),a为模板中的索引数组变量名,b为数组变量的元素所对应的值
//["Name"]=> array(1) { [0]=> string(4) "Fred" }
//    [Name] => Array
//		  (
//            [0] => Fred
//        )

$smarty->append('Name','Fred');
//数组的下标为数组变量名,
//
//    [name] => Array
//        (
//            [0] => zhao
//        )
//
//    [age] => Array
//        (
//            [0] => 20
//        )
$smarty->append(array('name' => 'zhao', 'age' => 20));
//    [user] => Array
//        (
//            [0] => Array
//                (
//                    [name] => zhao
//                    [age] => 20
//                )
//        )
$smarty->append('user',array('name' => 'zhao','age' => 20));



$smarty->display('db/math.html');	//显示模板

//$smarty->clear_all_assign();	
//清空smarty模板assign赋值的所有变量和值

$smarty->clear_assign("xpx");
//清除指定的assign分配的变量和值

//$smarty->clear_all_cache();
//清除所有模板的cache

//$smarty->clear_cache(string template [, string cache id [, string compile id [, int expire time]]]);
//清除指定模板的cache

//$smarty->clear_compiled_tpl([string tpl_file]);
//清除指定模板的编译版本,如果不指定tpl_file,则表示清除所有已编译模板

//$smarty->clear_config([string var]);
//清除所有配置变量,如果指定了变量名称,则只清除所指定的配置变量。

$arr = $smarty->get_template_vars();	//显示模板中所有变量和值

echo '<pre>';
print_r($arr);
echo '</pre>';

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值