|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
waro Smarty Regular
Joined: 12 Jun 2008 Posts: 38
|
Posted: Wed Sep 21, 2011 10:35 pm Post subject: cache_id not working, probably the flaw on my PHP logic |
|
|
Hi,
I've been setup my site using Smarty cache using different cache_id for different modules, and most of them working fine, but one particular peculiar module/cache_id.
In this module there are 4 different URLs or actions, i.e:
1. ./?mod=blog&cat=1
2. ./?mod=blog&cat=1&page=2 => pagination of URL#1
3. ./?mod=blog&cat=1&year=2005, and
4. ./?mod=blog&cat=1&year=2005&page=2 => pagination of URL#3
The first two were working fine, but not the last two.
Here my snippet to generate cache_id, for that module:
Code: | ...
elseif (isset($_GET['mod']) == 'blog' && isset($_GET['cat']))
{
if (!empty($_GET['year']) && !empty($_GET['page']))
{
$my_cache_id = $_GET['mod'].$_GET['cat'].$_GET['year'].$_GET['page'];
}
elseif (!empty($_GET['year']))
{
$my_cache_id = $_GET['mod'].$_GET['cat'].$_GET['year'];
}
elseif (!empty($_GET['page']))
{
$my_cache_id = $_GET['mod'].$_GET['cat'].$_GET['page'];
}
else
{
$my_cache_id = $_GET['mod'].$_GET['cat'];
}
}
... |
From the HTTP headers if I go to URL#3, it would read :
Code: | GET /?mod=blog&cat=1&year=2005 HTTP/1.1 |
But it would display like URL#1 or display correctly if URL#1's cache not generated the first time. It wass as if it didn't GET 'year'.
Maybe this is not Smarty problem but will someone point out where's the flaw of my code here?
Thanks. |
|
Back to top |
|
rodneyrehm Administrator
Joined: 30 Mar 2007 Posts: 674 Location: Germany, border to Switzerland
|
Posted: Wed Sep 21, 2011 10:54 pm Post subject: |
|
|
Code: | elseif (isset($_GET['mod']) == 'blog' && isset($_GET['cat'])) |
isset($_GET['mod') returns a boolean, 'blog' evaluates to the boolean true. see Code: | $_GET['mod'] = 'foo';
if (isset($_GET['mod']) == 'blog') {
echo 'but blog is not foo!';
} |
---
your cache_id segments are not delimited. you should put | between the elements. To make things a bit simpler, try something like Code: | $cache_id = array(
$_GET['mod'],
$_GET['cat'],
isset($_GET['year']) ? $_GET['year'] : 'no-year',
isset($_GET['page']) ? $_GET['page'] : 'no-page',
);
$cache_id = join('|', $cache_id);
var_dump($cache_id); |
_________________ Twitter |
|
Back to top |
|
waro Smarty Regular
Joined: 12 Jun 2008 Posts: 38
|
Posted: Thu Sep 22, 2011 2:56 am Post subject: |
|
|
Thank you, your code make easy in my eyes. |
|
Back to top |
|
|
|
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
|