2016-01-20 38 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