The Zend\\Session Save Handler tutorial gives an example for DbTableGateway in which they create a TableGateway with an undefined $adapter variable. I want to use the handler to
I have this code for save a session to a db table.
'service_manager' => array(
'factories' => array(
'Zend\Session\SessionManager' => function (\Zend\ServiceManager\ServiceManager $sm) {
$sessionConfig = new \Zend\Session\Config\SessionConfig();
$sessionConfig->setOptions(
array(
'use_cookies' => true,
'name' => 'ed2',
'gc_maxlifetime' => 1728000
)
);
/* @var $adapter \Zend\Db\Adapter\Adapter */
$adapter = $sm->get('Zend\Db\Adapter\Adapter');
$tableGateway = new \Zend\Db\TableGateway\TableGateway('session', $adapter);
$saveHandler = new \Common\Session\SaveHandler\DbTableGateway(
$tableGateway,
new \Zend\Session\SaveHandler\DbTableGatewayOptions()
);
$sessionManager = new \Zend\Session\SessionManager($sessionConfig);
$sessionManager->setSaveHandler($saveHandler);
$sessionManager->start();
return $sessionManager;
},
)
)
Config for db
'db' => array(
'driver' => 'Pdo_Mysql',
'database' => 'release',
'username' => 'username',
'password' => 'password',
'hostname' => '127.0.0.1',
'driver_options' => array(
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\''
)
),
'service_manager' => array(
'factories' => array(
'Zend\Db\Adapter\Adapter' => function (\Zend\ServiceManager\ServiceManager $serviceManager) {
$adapterFactory = new Zend\Db\Adapter\AdapterServiceFactory();
$adapter = $adapterFactory->createService($serviceManager);
Zend\Db\TableGateway\Feature\GlobalAdapterFeature::setStaticAdapter($adapter);
return $adapter;
}
)
)