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

Variables not recognized in 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 -> Bugs
View previous topic :: View next topic  
Author Message
eelco
Smarty n00b


Joined: 19 Aug 2015
Posts: 3

PostPosted: Wed Sep 23, 2015 4:35 pm    Post subject: Variables not recognized in cache Reply with quote

I am further implementing the cache functions of Smarty, and now the variables are not recognized in cache.

When my page is generated the first time, so not using cache, the page is displayed correctly. When I refresh, the cache is being used, and the variables are not recognized any more. I get the following error:

Code:
Notice: Undefined index: Products in /home/lib/smarty/smarty-3.1.27/sysplugins/smarty_cacheresource_keyvaluestore.php(104) : eval()'d code on line 90


My code (in short):

Code:

if(!$smarty->isCached('category.html', 'key'))
{
   /**
   * Load data
   */
   $x = array();
   
   /**
   * Save variable
   */
   $smarty->Assign('Products', $x);
}   

/**
* Display page
*/
$smarty->Display('category.html', 'key');


EDIT: I now found I have a {nocache}-part in the template where I call the $Products variable. I believe this produces the error. Is there a way around this?
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Wed Sep 23, 2015 4:53 pm    Post subject: Reply with quote

Sounds like your variable somehow left 'nocache'd. Can't tell without seeing exact template code.

Also, make sure you are not misspelling method names.

P.S.
And that caching is actually enabled, and not overridden.
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Thu Sep 24, 2015 7:13 pm    Post subject: Reply with quote

Variables used in {nocache} sections must be always assigned, not only when the cache is invalid. Thats the purpose of a nocache section that variables are dynamic and not cached......
Back to top
View user's profile Send private message
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 -> Bugs 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