如何在控制器操作中使用Session Container?

时间:2013-07-26 06:22:58

标签: zend-framework2 session-timeout

我在网上搜索。我想在Action中使用session。我有代码:

在module.config.php中:

return array(
            'remember_me_seconds' => 360,
            'name'                => 'zf2',
            'use_cookies' => true,
            'cookie_httponly' => true,
    ),
);
在Module.php中

public function onBootstrap(MvcEvent $e)
    {

        $config = $e->getApplication()->getServiceManager()->get('Configuration');

        $sessionConfig = new SessionConfig();
        $sessionConfig->setOptions($config['session']);
        $sessionManager = new SessionManager($sessionConfig);
        $sessionManager->start();

        /**
         * Optional: If you later want to use namespaces, you can already store the
         * Manager in the shared (static) Container (=namespace) field
         */
        Container::setDefaultManager($sessionManager);
    }

在控制器中:

    public function updatesessionAction(){

            $key = $this->getEvent()->getRouteMatch()->getParam('key');
            $value = $this->getEvent()->getRouteMatch()->getParam('value');

            $this->userSession = new Container($this->sessionNameSpace);
            $this->userSession->offsetSet($key,$value);
}

它运行,但时间总是= 180秒。像我配置不是360秒。 我不知道哪里有值180.我需要把它设置为配置?

0 个答案:

没有答案