我有这样的代码:
$sessionOptions = new SessionDbSavehandlerOptions();
$sessionOptions->setDataColumn('data')
->setIdColumn('id')
->setModifiedColumn('modified')
->setLifetimeColumn('lifetime')
->setNameColumn('name');
$application = $event->getApplication();
$serviceManager = $application->getServiceManager();
$dbAdapter = $serviceManager->get('Zend\Db\Adapter\Adapter');
$sessionTableGateway = new TableGateway('zf2_sessions', $dbAdapter);
$sessionGateway = new DbTableGateway($sessionTableGateway, $sessionOptions);
$config = $serviceManager->get('Configuration');
$sessionConfig = new SessionConfig();
$sessionConfig->setOptions($config['session']);
$sessionManager = new SessionManager($sessionConfig);
$sessionManager->setSaveHandler($sessionGateway);
$sessionManager->start();
Container::setDefaultManager($sessionManager);
效果很好,但此代码在文件中的onBootstrap()
方法中。Module.php
有没有更好的方法(地点?)来实现会话?控制器插件是用于控制器的,那么这些是什么?