Smarty缓存无法正常工作?

时间:2009-06-06 17:04:03

标签: php caching smarty

当我启用缓存时,我在我的项目中使用Smarty它似乎不起作用。 我使用以下结构:

  

index.php - display(index.tpl)

     

index.tpl - {include   文件= $ page_center}

     

?module = product -   $ smarty-> assign(“page_center”,   “product.tpl”);

在product.php中,模板product.tpl必须加载到index.tpl的中心。 当我启用缓存时,它仍然显示默认内容而不是product.tpl。禁用缓存时,它可以正常工作。启用缓存时有什么问题?

3 个答案:

答案 0 :(得分:8)

您需要为每个页面使用唯一的缓存ID才能使其正常工作:

$cacheID = 'some_unique_value_for_this_page';
$smarty->assign('page_center', 'product.tpl');
$smarty->display('index.tpl', $cacheID);

根据您在问题中提供的示例,使用查询字符串中的模块名称作为缓存ID的基础是有意义的。

有关Smarty手册的更多信息:http://www.smarty.net/manual/en/api.display.php

答案 1 :(得分:0)

你需要创建一个动态模块!

function smarty_block_dynamic($param, $content, &$smarty) {
    return $content;
}

然后

$smarty = new Smarty
$smarty->register_block('dynamic',
                        'smarty_block_dynamic',
                        false /* this block wont be cached */);

和你的tpl

Hello {$name}

this is your las update

{/dyamic}
{include file="some/dynamic/thing.tpl"}
{/dynamic}

答案 2 :(得分:0)

在尝试解决智能缓存问题之前,即如果没有发生缓存,请检查您的templates_c文件夹是否具有对所有

的读写权限
相关问题