Using PdoSessionStorage in Symfony2
13. April 2011 in Sessions, Symfony2
Update: I wrote a more detailed cookbook for the Symfony2 documentation which is online from today: Documentation
As I told you in my last blog entry, I had the problem that there is no documentation on how to use the PdoSessionStorage in Symfony2. I opened a question on Stackoverflow but there was no one who could help me. Yesterday I found some time to investigate this problem. After reading the Symfony2 sources I found my way. So here it is:
All you need to do is to change some parameters in the app/config/config.yml file (or one of the environment dependend config-files):
|
1 2 3 4 5 6 7 8 9 |
session:
default_locale: %locale%
lifetime: 3600
auto_start: true
storage_id: pdo
db_table: session
db_id_col: session_id
db_data_col: session_value
db_time_col: session_time |
- db_table: The name of the session table in your database
- db_id_col: The name of the id column in your session table (VARCHAR(255))
- db_data_col: The name of the value column in your session table (TEXT or CLOB)
- db_time_col: The name of the time column in your session table (INTEGER)
Now you have to define a PDO connection in the config.yml. For that create a new service:
|
1 2 3 4 5 6 7 |
services:
pdo_connection:
class: PDO
arguments:
dsn: "mysql:dbname=sf2demo"
user: root
password: |
That’s it
DuoSRX said on 13. April 2011
Nice post !
I actually also found out how to use PdoSessionStorage yesterday.
However I still can’t manage to get it working with the Security Component. Basically I’m logged in and then instantly logged out.
Any idea ?
Timo Haberkern said on 13. April 2011
Never tried it with Security. Need to check it.
Lorene said on 13. November 2011
Felt so hopeless looking for answers to my qsueiotns…until now.
padma said on 8. March 2012
hai,
how to add another field like db_data_col.i want to insert url of the current page in session table using session_set_save_handler in pdosessionstorage class in symfony2.any one please help me