Leah Collins
Leah Collins

Reputation: 637

Setting Cakephp sessions to database

I just migrated my app from cakephp1.3 to cakephp2.0. I have problem configuring session to database.

I changed session configuration in core.php

Configure::write('Session', array(
    'defaults' => 'database',
        'handler' => array(
        'model' => 'Session'
        )
));

I have a db table a sessions. Is there anything I missed. When I write sessions on login and redirects fine and I can read session variable fine. But on page refresh, the session is deleted.

Upvotes: 4

Views: 4358

Answers (1)

kittycat
kittycat

Reputation: 15045

From my understanding, you are trying to use Cake's default database session handling, and you are not using a custom handler model, if so:

Set these configuration options for Cake to use the database sessions in app/config/core.php:

Configure::write('Session', array(
    'defaults' => 'database'
));

Make sure you run this for the database you will be using to create the proper table, as Cake will store the sessions there:

CREATE TABLE cake_sessions (
  id varchar(255) NOT NULL default '',
  data text,
  expires int(11) default NULL,
  PRIMARY KEY  (id)
);

Upvotes: 6

Related Questions