I have a User object that, after successful authentication, is refueled into the session (without security information) for easy calling and to determine if we have an authenticated user or an anonymous session. There are several ways in which a user can change some or all of his or her information, and I would like to keep this session current. The obvious answer is updating the value in the afterSave() callback, but that of course violates MVC.
Is there any other way to capture each change in one place, so I don’t need to record the session in all places? I cannot think of anything, and I could not find any other ideas. Am I the only person trying to do something like this?
Thanks.
The final decision . I marked Neilcrookes answer as an answer, to be honest, because it doesn't seem to be the best way. Since this method violates my OCD feelings, though, I took a slightly different path. I decided that my User::authenticate() method returns an authenticated user object to the caller so that he can do whatever he wants with it. One of the things that users want to do is to discard this value in the session. This is redundancy, but it is very, very limited. In my opinion, it was better than accessing a session from a model (although it is, of course, damned if you do, damned if you don't have a script).
source share