How to use cookie in Zend Framework 2? [closed]

穿精又带淫゛_ 提交于 2019-12-01 01:31:30

simply use the rememberMe() method on the SessionManager to set a cookie

See SessionManager Code on line 260

there also is forgetMe() to remove the cookie

additionally you can configure the defaults for your session manager like this:

Module.php

public function onBootstrap(\Zend\EventManager\EventInterface $e)

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

    $sessionConfig = new SessionConfig();
    $sessionConfig->setOptions($config['session']);
    $sessionManager = new SessionManager($sessionConfig, null, null);
    Session::setDefaultManager($sessionManager);
}

module.config.php

return array(
    'session' => array(
        'remember_me_seconds' => 2419200,
        'use_cookies' => true,
        'cookie_httponly' => true,
    ),
);

See this class for a complete list of configuration options:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!