如何在Zend Framework 2中使用Cookie? [英] How to use cookie in Zend Framework 2?

查看:86
本文介绍了如何在Zend Framework 2中使用Cookie?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不明白如何在ZF2中使用Cookie?有人可以建议一些带有set的链接并获取Cookie吗?

I cant understand how to use cookies in ZF2? Can some one advise some links with set and get cookie?

推荐答案

只需在SessionManager上使用rememberMe()方法来设置cookie

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

参见260行上的 SessionManager代码

还有forgetMe()可以删除Cookie

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:

这篇关于如何在Zend Framework 2中使用Cookie?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆