Smarty缓存无法正常工作?

meh*_*hdi 3 php caching smarty

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

index.php - display(index.tpl)

index.tpl - {include file = $ page_center}

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

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

geo*_*ock 8

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

$cacheID = 'some_unique_value_for_this_page';
$smarty->assign('page_center', 'product.tpl');
$smarty->display('index.tpl', $cacheID);
Run Code Online (Sandbox Code Playgroud)

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

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