Welcome Guest, Not a member yet? Register   Sign In
Temp data that must be destroyed at end of lifecycle
#1

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
Reply
#2

Which version of CodeIgniter?
Reply
#3

CI3

Vincent
Reply
#4

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.
Reply
#5

@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
Reply
#6

(06-26-2020, 09:15 AM)vincent78 Wrote: @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

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.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB