Re:Re:Re:Re:[BEGINNER] Question about caching
| From: | Andrei Zmievski | Date: | Mon, 31 Dec 2001 14:06:12 +0000 |
| Subject: | Re:Re:Re:Re:[BEGINNER] Question about caching | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-2451@lists.php.net to get a copy of this message | ||
On Fri, 28 Dec 2001, Brian E. Lozier wrote:
> >Well, set $tpl->caching = false right before you do display() and it
> >should work.
>
> Yeah, but it doesn't. It puts absolutely no content in place of {$Content} (just blank).
> It's like, since I
> set caching to false, it discards all cached content that I have previously retrieved.
Well, of course. Look what you are asking it to do:
if(!$tpl->is_cached('index.tpl', $REQUEST_URI)) {
// do my db calls
$dbInfo = mysql_db_junk();
// assign it
$tpl->assign('dbInfo', $dbInfo);
// fetch the right template to include it
$tpl->assign('Content', $tpl->fetch('index.tpl', $REQUEST_URI));
}
$tpl->display('main.tpl');
If index.tpl is not cached, everything is fine - it will fetch the
its content, assign them to $Content variable and display main.tpl. If
it is cached, no fetching or assignment takes place, and since Smarty
does not cache the assigned variables, $Content is empty by the time you
get to displaying main.tpl. It's a simple logic error. Try it like this:
if(!$tpl->is_cached('index.tpl', $REQUEST_URI)) {
// do my db calls
$dbInfo = mysql_db_junk();
// assign it
$tpl->assign('dbInfo', $dbInfo);
}
// fetch the right template to include it
$tpl->assign('Content', $tpl->fetch('index.tpl', $REQUEST_URI));
$tpl->display('main.tpl');
-Andrei
"When I get a little money, I buy books;
and if any is left I buy food and clothes." -- Erasmus