» Extending the Symfony2 session
By COil on Friday 6 January 2012 21:16 ::
symfony ::
Permalink ::
Tags ::
session
|
snippets
|
symfony
|
symfony2
|
View comments
Hi symfonians !
If you are used to symfony1, you probably noticed that you don't have a myUser
class to handle the user session. It's generally useful so you don't have to handle directly with session attributes and you can also have shortcuts. Well it's quiet easy to have such a class in Symfony2:
Declare your own session class as the framework level in your app/config.yml config file:
And now create your own mySession class which extends the default Symfony2 session class:
And your done.
PS: The class can be stored in another location, I'm not sure which is the best ?
PS2: The service could also be loaded at the Bundle level.







» Comments
I think extending session for this case is a "symfony1 bad habit", because it's not storage agnostic.
Personnaly, I create a classHandler service which handle the saving/retrieving process of a classContainer (in your case it would be an AnswerCollection).
Having a classHandler allow you to change easily where the container/collection is saved without touching the logic.
Hi Cethy, sorry for the late answer. Humm I am not sure to understand what you mean, in this case I want to have the storage of "answers history" to be the same as the session storage.
In your example, default locale for the session will always be "en" as you do not pass the second parameter which defines default locale setting. Just expand arguments like this:
arguments:
@Dante: You are true. Fixed.