![]() |
Model Static variable reset on page refresh - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Model Static variable reset on page refresh (/showthread.php?tid=61133) |
Model Static variable reset on page refresh - El Forum - 09-24-2014 [eluser]Unknown[/eluser] Hello, I have a problem in my application using CodeIgniter. This is what I want: In my model I make a select all from a table on data base. In an attempt to improve the app perform I planned to make this selection only once and store the result array in an static variable, this way, this variable will be returned in following calls. This is the problem: Every time I refresh the page my model is reloaded and my static variable receives null, this way, every time the data base select is done. How can I resolve this?? Model: Code: class Account extends CI_Model { My log: DEBUG - 2014-09-25 00:01:24 --> Config Class Initialized DEBUG - 2014-09-25 00:01:24 --> Hooks Class Initialized DEBUG - 2014-09-25 00:01:24 --> Utf8 Class Initialized DEBUG - 2014-09-25 00:01:24 --> UTF-8 Support Enabled DEBUG - 2014-09-25 00:01:24 --> URI Class Initialized DEBUG - 2014-09-25 00:01:24 --> Router Class Initialized DEBUG - 2014-09-25 00:01:24 --> Output Class Initialized DEBUG - 2014-09-25 00:01:24 --> Security Class Initialized DEBUG - 2014-09-25 00:01:24 --> Input Class Initialized DEBUG - 2014-09-25 00:01:24 --> Global POST and COOKIE data sanitized DEBUG - 2014-09-25 00:01:24 --> Language Class Initialized DEBUG - 2014-09-25 00:01:24 --> Loader Class Initialized DEBUG - 2014-09-25 00:01:24 --> Helper loaded: url_helper DEBUG - 2014-09-25 00:01:24 --> Session Class Initialized DEBUG - 2014-09-25 00:01:24 --> Helper loaded: string_helper DEBUG - 2014-09-25 00:01:24 --> Session routines successfully run DEBUG - 2014-09-25 00:01:24 --> Controller Class Initialized DEBUG - 2014-09-25 00:01:24 --> Model Class Initialized DEBUG - 2014-09-25 00:01:24 --> >> Loading Account DEBUG - 2014-09-25 00:01:24 --> allAccountsArray is null DEBUG - 2014-09-25 00:01:24 --> File loaded: Deliverable/application/views/deliverable/index.php DEBUG - 2014-09-25 00:01:24 --> File loaded: Deliverable/application/views/templates/Default.php DEBUG - 2014-09-25 00:01:24 --> Final output sent to browser DEBUG - 2014-09-25 00:01:24 --> Total execution time: 0.2245 DEBUG - 2014-09-25 00:01:46 --> Config Class Initialized DEBUG - 2014-09-25 00:01:46 --> Hooks Class Initialized DEBUG - 2014-09-25 00:01:46 --> Utf8 Class Initialized DEBUG - 2014-09-25 00:01:46 --> UTF-8 Support Enabled DEBUG - 2014-09-25 00:01:46 --> URI Class Initialized DEBUG - 2014-09-25 00:01:46 --> Router Class Initialized DEBUG - 2014-09-25 00:01:46 --> Output Class Initialized DEBUG - 2014-09-25 00:01:46 --> Security Class Initialized DEBUG - 2014-09-25 00:01:46 --> Input Class Initialized DEBUG - 2014-09-25 00:01:46 --> Global POST and COOKIE data sanitized DEBUG - 2014-09-25 00:01:46 --> Language Class Initialized DEBUG - 2014-09-25 00:01:46 --> Loader Class Initialized DEBUG - 2014-09-25 00:01:46 --> Helper loaded: url_helper DEBUG - 2014-09-25 00:01:46 --> Session Class Initialized DEBUG - 2014-09-25 00:01:46 --> Helper loaded: string_helper DEBUG - 2014-09-25 00:01:46 --> Session routines successfully run DEBUG - 2014-09-25 00:01:46 --> Controller Class Initialized DEBUG - 2014-09-25 00:01:46 --> Model Class Initialized DEBUG - 2014-09-25 00:01:46 --> >> Loading Account DEBUG - 2014-09-25 00:01:46 --> allAccountsArray is null DEBUG - 2014-09-25 00:01:46 --> File loaded: Deliverable/application/views/deliverable/index.php DEBUG - 2014-09-25 00:01:46 --> File loaded: Deliverable/application/views/templates/w3Default.php DEBUG - 2014-09-25 00:01:46 --> Final output sent to browser DEBUG - 2014-09-25 00:01:46 --> Total execution time: 0.2424 Model Static variable reset on page refresh - El Forum - 09-25-2014 [eluser]CroNiX[/eluser] I'm not clear on what you're asking. Of course it gets reset to null when you refresh the page as it's a new request to the server. If you want it to always be populated, maybe you just need to run $this->selectAll() in the __construct. Of course you'll still get the null message in the logs once for each request where that model gets loaded. Model Static variable reset on page refresh - El Forum - 09-26-2014 [eluser]LuckyFella73[/eluser] For me it sounds like is looking for db caching. |