Question

I am trying to understand how to set up a Session Save Handler (with Zend/Doctrine) using a database table but I am a bit confused about how it all should work.

I found this proposal that I think it suits my needs as I am also working with Doctrine.

All is set up: the proper class, the database table and Doctrine Model. What I don't get is this part:

$config = array(
'tableName'         => 'Session',
'dataColumn'        => 'data',
'lifetimeColumn'    => 'lifetime',
'modifiedColumn'    => 'modified',
'primaryKeyColumn'  => 'id',
);

Zend_Session::setSaveHandler(new Zend_Session_SaveHandler_Doctrine($config));
Zend_Session::start();

I am confused here. Where should this part go? Can anyone please help? Or maybe point me to some useful tutorial to do this?

Was it helpful?

Solution

This should go in your main bootstrap class (application/Bootstrap.php). So I'd add something like this:

protected function _initDoctrineSession()
{
    $config = array(
        'tableName'         => 'Session',
        'dataColumn'        => 'data',
        'lifetimeColumn'    => 'lifetime',
        'modifiedColumn'    => 'modified',
        'primaryKeyColumn'  => 'id',
    );

    Zend_Session::setSaveHandler(new Zend_Session_SaveHandler_Doctrine($config));
    Zend_Session::start();
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top