我不明白如何在 ZF2 中使用 cookie?有人可以建议一些带有 set 和 get cookie 的链接吗?
只需使用rememberMe()
方法上的SessionManager
设置 cookie
See 会话管理器代码260号线
还有forgetMe()
删除cookie
另外,您可以像这样配置会话管理器的默认值:
模块.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);
}
模块.config.php
return array(
'session' => array(
'remember_me_seconds' => 2419200,
'use_cookies' => true,
'cookie_httponly' => true,
),
);
See 这个班有关配置选项的完整列表:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)