2016-01-20 48 views
1

我试图做一个“记住我”检查按钮来修复用户会话的时间超过配置中指定的生存期。我在NativeSessionStorage课程的帮助下使用symfony2会话。如何配置symfony2会话的生存期

$nativeSession = new NativeSessionStorage(
     array(
      'cookie_lifetime' => 3600*24*7 
     ) 
    ); 

当我尝试启动创建的会话时,symfony抛出此异常。

if($_SESSION){ 
     session_destroy(); 
     $nativeSession->start(); 
    } 

enter image description here

enter image description here

任何人都有权处理的申报这类会议。

+0

这不会帮助太多。我不想更改config.yml中的值,但直接在代码中。 – KubiRoazhon

+1

你为什么想这样做?配置是要走的路,因为在Symfony2中,您不是使用本地Session类,而是使用Symfony2 Session类。 – KhorneHoly

+0

我试图做一个“记住我”检查按钮来修复用户会话比配置中指定的生命周期更多的时间。 – KubiRoazhon

回答

3

如果您想在Symfony2中构建记忆功能,您可以在symfony2配置中为此功能定义更长的生命周期。有关其他信息,请参见documentation。也从那里取得的例子。

# app/config/security.yml 
security: 
    # ... 

    firewalls: 
     main: 
      # ... 
      remember_me: 
       secret: '%secret%' 
       lifetime: 604800 # 1 week in seconds 
       path: /
       # by default, the feature is enabled by checking a 
       # checkbox in the login form (see below), uncomment the 
       # following line to always enable it. 
       #always_remember_me: true