smarty局部缓存的解决办法

局部缓存

实时性要求比较高

例如:登陆用户名称

欢迎Admin登陆到****

例如:时间日期

解决步骤: 自定义函数(自定义插件)

第一种:插件形式

1) 指定该函数名称nocache

2) 新建文件./plugins/block.nocache.php

内容:

<?php

functionsmarty_block_nocache($args, $content){

return$content;}

?>

3)*.php

….

$tpl->assign(“date,date(“H:i:s”));

….

***.tpl

<{nocache}><{$date}><{/nocache}>

所有插件默认被缓存

Smarty. 在712 行

Else{

if($tag_command==nocache){

$this->_plugins['block'][$tag_command] =array($plugin_func, null, null, null, false);}

Else{

$this->_plugins['block'][$tag_command] =array($plugin_func, null, null, null, true);

}

}

第二种:php文件内自定义函数并注册

***.php

$tpl->register_block(“nocache”,”fun1”,false);

function fun1($args,$content){return$content;}

$tpl->assign(“date”,date(“H:i:s”));

****.tpl

<{nocache}><{$date}><{/nocache}>

第三种:smarty内建函数insert

定义一个inser标签要使用的处理函数

函数名格式为:

insert_xx(array $params, object &$smarty)

其中的xx是insert的name,也就是说,如果你定义的函数为insert_abc,则模板中使用方法为{insert name=abc}参数通过

$params传入

也可以做成insert插件,文件名命名为:insert.xx.php,函数命名为:smarty_insert_aa($params,&$smarty),xx定义同上

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值