smarty局部缓存

 

一、以插件形式

    指定该函数的名称,如:nocache。然后到plugins这个文件下建立块函数。(./plugins/block.nocache.php)命名文件的名字的时候要遵循自定义函数的要求。我们要在这个函数里把每次请求出来的部分内容显示出来,不让它生成缓存:

<?php

   function smarty_block_nocache($args, $content){

     return $content;}

 ?>

       在smarty里面所有的插件默认被缓存。所以这个文件也会被缓存。这时我们要修改Smarty_Compiler.class.php这个配置文件,在文件的712行的位置上会:“                 $this->_plugins['block'][$tag_command] = array($plugin_func, null, null, null, true); 。”这里把括号里面的true改成false,这样所有的插件就不会被自动生成缓存。如果我们不想把所有的插件都改成不被缓存的状态,只想我把写的block.nocache.php这个文件不被缓存。

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:

<?php
//本文件使用模版类
//首先包含该模板文件
include("init.inc.php");

//注册函数

$tpl->register_function("data","fun1");

//定义fun1函数

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

//分配变量

$tpl->assign("data",date("H:i:s"));

//调用模板文件
$tpl->display("a.html");

?>

       *  .  tpl:

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值