tags:

views:

43

answers:

1

I have an application that is authenticating against an external server in a filter. In that filter, I'm trying to set a couple of session attributes on the user by using Symfony's setAttribute() method:

$this->getContext()->getUser()->setAttribute( 'myAttribute', 'myValue' );

What I'm finding is that, if I dump $_SESSION immediately after setting the attribute. On the other hand, if I call getAttribute( 'myAttribute' ), I get back exactly what I put in.

All along, I've assumed that reading/writing to user attributes was synonymous with reading/writing to the session, but that seems to be an incorrect assumption. Is there a timing issue? I'm not getting any non-object errors, so it seems that the user is fully initialized.

Where is the disconnect here?

Thanks.

UPDATE

The reason this was happening is because I had some code in myUser::shutdown() that cleared out a bunch of stuff. Because myUser is loosely equivalent to $_SESSION (at least with respect to attributes), I assumed that the shutdown() method would be called at the end of each session. It's not. It seems to get called at the close of each request which is why my attributes never seemed to get set.

Now, though, I'm left wondering whether there's a session closing callback. Anyone know?

A: 

Depending on how you are doing your session handling the session storage class has two methods, sessionGC (called on garbage collection) and sessionDestroy.

You can create your own session class extending what ever one you are using currently, we use Doctrine/PDO. The default is sfSessionStorage.

To change what class you use edit factories.yml:

all:
  storage:
    class: mySuperNewSessionStorageClass
johnwards
Rob Wilkerson