Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

querystrings have no effect on my ouput - silly cache

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
gtgibson
Smarty Rookie


Joined: 30 Jul 2003
Posts: 9
Location: New Zealand

PostPosted: Thu Jul 31, 2003 9:19 am    Post subject: querystrings have no effect on my ouput - silly cache Reply with quote

query strings...

I have a php file with an SQL query
<?php
# retrieve an article, and author information
$query = "SELECT * from articles WHERE articles.ID = ".$_GET["ID"]." LIMIT 1";
$article = mysql_fetch_array($result, MYSQL_BOTH);
$smarty->assign('article',$article);

$smarty->display('article.tpl');
?>

The problem I have is that when I view the pages on the site view the article.tpl file, e.g. when I ask for:

article.php?ID=1

it works great the first time, after that the template isn't recompiling, and I keep getting the original article no matter what article ID I pass in the querystring. e.g:

article.php?ID= 2

When I resave the template file, it displays the new article. Obviously this has something to do with caching, but how can I get around this? Is smarty not designed to retrieve information this way? What shoudl I be doing?

Thanks,

GG
_________________
I suck at web development.
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Thu Jul 31, 2003 9:33 am    Post subject: Reply with quote

if you set $smarty->caching=true you have to supply a unique cache_id if you want to display different things. try:
$smarty->display('index.tpl', $_GET['ID']);

see: http://smarty.php.net/manual/en/caching.multiple.caches.php for reference.

greetings
messju
Back to top
View user's profile Send private message Send e-mail Visit poster's website
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Thu Jul 31, 2003 10:07 am    Post subject: Reply with quote

umm, my advice was only a quick fix.
you shouldn't pass get-parameters directly as cache-ids, but check them for sanity. in your case:
$smarty->display('article.tpl', ($article) ? (int)$_GET['id'] : 0);
may be sufficient, but (as always) YMMV Smile
Back to top
View user's profile Send private message Send e-mail Visit poster's website
gtgibson
Smarty Rookie


Joined: 30 Jul 2003
Posts: 9
Location: New Zealand

PostPosted: Thu Jul 31, 2003 10:09 am    Post subject: Reply with quote

Perfekt!
_________________
I suck at web development.
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
gtgibson
Smarty Rookie


Joined: 30 Jul 2003
Posts: 9
Location: New Zealand

PostPosted: Thu Jul 31, 2003 10:09 am    Post subject: Reply with quote

YMMV Question
_________________
I suck at web development.
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
gtgibson
Smarty Rookie


Joined: 30 Jul 2003
Posts: 9
Location: New Zealand

PostPosted: Thu Jul 31, 2003 10:23 am    Post subject: Reply with quote

what does the " : 0" part do?

actually, now that I take a deeper look... what does most of that mean inside $smarty->display():

$smarty->display('article.tpl', ($article) ? (int)$_GET['id'] : 0);
_________________
I suck at web development.
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Thu Jul 31, 2003 10:37 am    Post subject: Reply with quote

YMMV: your mileage may vary Smile

"($article) ? (int)$_GET['id'] : 0" is the ?-operator borrowed from c. it says: if $article is someting true use "(int)$_GET['id']" (which means $_GET['id'] converted to an integer value) else use "0" as a cache_id.

overall the example above is a short-hand for:
[php:1:e71c07ec99]
if ($article) {
$cache_id = (int)$_GET['id'];
} else {
$cache_id = 0;
}
$smarty->display('article.tpl', $cache_id);
[/php:1:e71c07ec99]
which is virtually the same Smile
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP