热搜:NVER node 开发 php

关于smarty缓存问题

2024-09-19 10:25:01
关于smarty缓存问题

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模板标签”,“你的自定义函数”)