当实时性要求比较高的时候(例如登录:欢迎。。。。登录)
解决的办法:局部不缓存;
1、第一种方法:
1)、指定该函数的名称:nocache
2)、在插件目录下(plugins)创建一个块 命名为:block.nocache.php
该函数中的内容:
<?php
function smarty_block_nocache($args,$content){
return$content;
}
?>
*.Php
$tpl->assign(“data”.date(“H:i:s”));
*.tpl
<{nocache}><{$data}><{/nocache}>
写成插件时,要配置Smarty_Compiler.class.php 让函数为:nocache的当执行它的时候不被缓存; 操作如下:文件名: Smarty_Compiler.class.php
行数: 713---719
针对smarty版本: 3.1.4
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); false代表当执行该块时是不被缓存的。
function fun1($args,$content){ return $content; }
$tpl->assign("time",date("H:i:s"));
*.tpl
<{nocache}><{$time}><{/nocache}>
第三种:smarty内建函数insert:
*.php
function insert_fun1(){return date(“H:i:s”); }
注意:用内建函数insert时,函数名都要加上insert_你要定义的函数名
*.tpl
<insert name=”fun1”>