Adding more data(columns) to CDbHttpSession

Hi,

I have started to use CDbHttpSession for the session handling. It works very well but I want to store more data in the session table. I know I can use the add() method on the session but that would put the data in to the data column of the session. I want to store information like what action the current user is performing at the moment, the last access time for the user. I also want to build an interface on top of this which queries the  session table and gives the administrator a list of all the active users, their last access time and the last action they performed.

I could implement all this like a some kind of spyBehaviour and write this data to a separate table in the data base but that would give me at least two writes to the database for every visitor, I guess that would not be necessary if I could store this data directly in the session.

My thought here is to override the write session method in CDbHttpSession to add specific session data to separate columns in the session table instead of just adding it to the data column.

There could be a new method called something like add2Column("lastAction", "updatePassword") which runs add("lastAction", "updatePassword") and after that populates the separate column lastAction in the session table.

Is this a good idea or can it be done in a better way?

Thanks

/John

Hi,

please read this topic: http://www.yiiframew…opic,922.0.html

Thanks qwerty, it looks like I am on the right path. It is probably best to save the the specific data like lastAction both in the data column and in the specific column. That way I don't have to worry about the read scenario since it will work straight out of the box and I will still have access to the extra data running queries on the session table.

It might also be a good idea to extract the userId to a separate column so I easily can join the users to the sessions.

/John