Smarty忽略cache_id?

时间:2011-04-03 10:49:38

标签: php caching smarty

因为我想在某些网站中使用动态元素我想要智能缓存,所以我想我会使用smarty isCached()函数的第二个参数和一个像“parameter1.parameter2.parameter3”这样的Id。 但出于某种原因,智能缓存仅一次,然后忽略参数和动态内容提供相同的页面。

可能是我的问题的根源是什么?

代码:

.tpl文件:

extends file="1_layout.tpl"}
{block name=title}domain.com - index{/block}
{block name=content} <html here> {/block}

.php文件:

$view = new Smarty(); 
$view->caching = true; 

$id = "index_"; 
if(isset($_SESSION['userid'])){ 
   $id .= "loggedIn";
}else{
   $id .= "guest"; 
} 
$id .= $_COOKIE['filter']; 

if(!$view->isCached('1_index.tpl', $id)) {
   get and assign some data
} 

$view->display('1.index.tpl');

1 个答案:

答案 0 :(得分:2)

您还需要将缓存ID添加到显示调用中。

$view->display('1.index.tpl', $id);