【问题标题】:How to use cookie in Zend Framework 2? [closed]如何在 Zend Framework 2 中使用 cookie? [关闭]
【发布时间】:2012-10-03 11:27:15
【问题描述】:

我不明白如何在 ZF2 中使用 cookie?有人可以建议一些带有 set 和 get cookie 的链接吗?

【问题讨论】:

  • de.php.net/manual/de/features.cookies.php 此处没有 Zend 特定的内容... 考虑到您有多少入门级问题,可能会建议您学习基本的 OOP PHP5 编程 - 在 ZF 之外:S
  • 我知道如何在 ZF 之外使用 cookie,但它在 Zf2 中是如何工作的?
  • 所以我知道它是如何工作的如何关闭一个问题?
  • 您应该写下它的工作原理作为答案,以供可能寻找相同问题的其他人使用

标签: zend-framework2 httpcookie


【解决方案1】:

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

参见第 260 行的SessionManager Code

还有forgetMe()可以删除cookie

此外,您还可以像这样为会话管理器配置默认值:

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,
    ),
);

有关配置选项的完整列表,请参阅 this class

【讨论】:

    猜你喜欢
    • 2011-12-13
    • 1970-01-01
    • 1970-01-01
    • 2013-01-14
    • 1970-01-01
    • 2014-10-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多