![]() |
proper place to insert code - 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: proper place to insert code (/showthread.php?tid=23305) |
proper place to insert code - El Forum - 10-06-2009 [eluser]Marc Arbour[/eluser] Dear CI community. I need help with the fact I have a small learning disability that prevents me from going through the user_guide or reading extensively on forums. I get confused too quickly and tend never to find my answer. But I am not stupid since I have created 2 cool websites with the help of CodeIgniter. I just need to be pointed in the right direction. That's all. What I need as an answer: I need for you just to tell me, as examples, 1- this should go in a class that should work this way 2- this should go in a helper that should be loaded in such a maner 3- anything that tells me how and what... I'll manage with reading/learning alone afterwards. What is, in your opinion, the best place to insert code to be executed "once a day"? (or, if need be, more often but not at every page view) Explanations: Once a day I need to delete specific records from a table in a database. I would like this to be cron independant in case we move the website to another server. Requirements: It needs to be in a place where database connection is already done since it's one single line as this one: Code: $query = $this->db->query('delete some records where condition is met'); Limitations: I tried putting in controllers initialization in some "more popular" controller, but the downfall is that I need to put it almost everywhere to garantee it's executed at least once daily when only once should be sufficient. Thus freeing server resources. Thanks for helping out. Marc. proper place to insert code - El Forum - 10-06-2009 [eluser]sophistry[/eluser] you are overcomplicating it for the wrong reason. i strongly suggest that you just create a new controller and call it (via curl or wget) using cron once-per-day (your stated requirement). it sounds like you know how to use cron to call web pages... it seems like trading a little problem for a big one to call a function at every page request just to make sure it runs once-a-day... if/when you move the website to another server, just update the cron job. proper place to insert code - El Forum - 10-06-2009 [eluser]Zack Kitzmiller[/eluser] I have a PHP file that lives outside of codeigniter. It has various routines in it in that are all executed via cron. (update statement balances, delete inactive users, etc). I completely agree with sophistry. You're completely over complicating this. |