对不需要缓存的地方,我们可以通过insert block ,插件block 法来解决局部缓存问题
1,insert 法
然后在模板中:
{insert name="get_current_time"}
2,动态block 法
在模板中:
{nocache}
{$smarty.now}
{/nocache}
3,插件block 法
在Smarty/plugins目录下建一个文件
block.nocache.php 内容如下(在php兄弟连的smarty高级缓存技术里面是用block_nocache.php,应该修正下):
然后在需要修改一个文件\libs\Smarty_Compiler.class.php 第712行
1,insert 法
定义一个函数显示时间的:
function insert_get_current_time(){
$timestamp=empty($timestamp)?time():$timestamp;
$timeoffset=(int) '+8';
return $ret=gmdate("Y-n-j g:ia", $timestamp + $timeoffset * 3600);
}
然后在模板中:
{insert name="get_current_time"}
2,动态block 法
//部分缓存
function smarty_block_nocache($param, $content, $smarty)
///function smarty_block_nocache($param, $content, &$smarty) 也看到这样写的
{
return $content;
}
$smarty->register_block('nocache', 'smarty_block_nocache', false);
在模板中:
{nocache}
{$smarty.now}
{/nocache}
3,插件block 法
在Smarty/plugins目录下建一个文件
block.nocache.php 内容如下(在php兄弟连的smarty高级缓存技术里面是用block_nocache.php,应该修正下):
<?php
function smarty_block_nocache($param, $content, $smarty)
{
return $content;
}
?>
然后在需要修改一个文件\libs\Smarty_Compiler.class.php 第712行
$this->_plugins['block'][$tag_command] = array($plugin_func, null, null, null, true);
改为
if('uncache'==$tag_command){
$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);
}