include("main.inc.php");
$smarty->caching=true;
$smarty->cache_lifetime="60*60*123";
$id=$_GET['id'];
$mysqli=new mysqli("localhost","root","123456","test");
$query="select * from user where id=$id";
if(!$smarty->is_cached("demo2.tpl",$id))
{
echo "sfd";
$result=$mysqli->query($query);
$arr=$result->fetch_assoc();
$smarty->assign("arr",$arr);
}
//如果不設定display的第二個參數,顯然每次只會唯讀取緩衝你檔案,這不是我們想要看的結果
//$smarty->display("demo2.tpl");
//啟用多頁面的緩衝
$smarty->display("demo2.tpl",$id);
?>
為什麼會報錯,,
Fatal error: Uncaught exception 'SmartyException' with message 'Call of unknown method 'is_cached'.' in D:\server\Apache2.2\htdocs\sutra\Smarty\sysplugins\smarty_internal_templatebase.php:755 Stack trace: #0 [internal function]: Smarty_Internal_TemplateBase->__call('is_cached', Array) #1 D:\server\Apache2.2\htdocs\sutra\smart\demo2.php(8): Smarty->is_cached('demo2.tpl', '19') #2 {main} thrown in D:\server\Apache2.2\htdocs\sutra\Smarty\sysplugins\smarty_internal_templatebase.php on line 755
回複討論(解決方案)
你在這開啟緩衝,瀏覽一次還會重建一次,你分配變了,緩衝也跟著變。你自己定義個時間看看。
你在這開啟緩衝,瀏覽一次還會重建一次,你分配變了,緩衝也跟著變。你自己定義個時間看看。
怎麼定義啊,我就是那判斷錯了,,那方法應該是這樣的吧
請檢查你的 smarty 的版本號碼
is_cached 方法只適用於 smarty 3
對於 smarty 2 是 isCached
我的smarty 3, 下載的包是Smarty-3.1.11.tar.gz,使用 is_cached 提示:Fatal error: Uncaught exception 'SmartyException' with message 'Call of unknown method 'is_cached'.' ,但使用 isCached 能正常工作。
好吧 情況是這麼個情況 smarty3.x這個版本已經和smarty2.x有所區別了 smarty3.x自訂函數要用$smarty->registerPlugin(“function”,“tpl模板標籤”,“你的自訂函數”)