snipersheep 2015-01-08 06:41 采纳率: 0%
浏览 1698

一个smary的简单问题哦

$smarty = new Smarty;

$smarty->force_compile = true;
$smarty->debugging = true;
$smarty->caching = true;
$smarty->cache_lifetime = 120;
if(!$smarty->isCached('index.tpl')){
echo 'no cache';

} else {
echo 'cache';
}
$smarty->display('index.tpl');

请教一下,为什么我这样设置每次都是 no cache.
在我的cache目录下己经生成了缓存文件。

  • 写回答

2条回答 默认 最新

  • save4me 2015-01-08 15:34
    关注

    参考isCached() — 检查模板是否已经缓存

    此函数仅在 $caching设置为Smarty::CACHING_LIFETIME_CURRENT或Smarty::CACHING_LIFETIME_SAVED的时候启用。 参见 缓存。

    <?php
    $smarty->setCaching(Smarty::CACHING_LIFETIME_CURRENT);
    
    if(!$smarty->isCached('index.tpl')) {
    // do database calls, assign vars here
    }
    
    $smarty->display('index.tpl');
    ?>
    
    评论

报告相同问题?