關於smarty緩衝問題

來源:互聯網
上載者:User
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模板標籤”,“你的自訂函數”)

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.