Temp data that must be destroyed at end of lifecycle - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: Temp data that must be destroyed at end of lifecycle (/showthread.php?tid=76845) |
Temp data that must be destroyed at end of lifecycle - vincent78 - 06-26-2020 Hello everybody, I want to create some data (for example, the object that represents the current user) that must be deleted at the end of the HTTP request, i.e. at the end of the CI lifecycle. How can I do ? Session->flashdata : the data is destroyed at the next request Session->tempdata : the data is destroyed after a specified time Thanks in advance Vincent RE: Temp data that must be destroyed at end of lifecycle - dave friend - 06-26-2020 Which version of CodeIgniter? RE: Temp data that must be destroyed at end of lifecycle - vincent78 - 06-26-2020 CI3 Vincent RE: Temp data that must be destroyed at end of lifecycle - dave friend - 06-26-2020 For v3 using Hooks is probably the way to go. Specifically for your needs, the post_controller hook. It's pretty well explained in the documentation, but let us know if you have implementation questions. RE: Temp data that must be destroyed at end of lifecycle - vincent78 - 06-26-2020 @Dave friend: Thanks for your answer I have an abstract class User Maybe, the best solution is to have a public static property in this class : $current_user and then, I can access like this: User::$current_user RE: Temp data that must be destroyed at end of lifecycle - dave friend - 06-26-2020 (06-26-2020, 09:15 AM)vincent78 Wrote: @Dave friend: Thanks for your answer Yes, that would work. Any data that is held only in (non-persistent) memory like a class instance object will automatically be destroyed when script execution ends. I assumed from the original question that you were using something that was potentially persistent like session data or a temp database table. |