2012-09-14 87 views
2

我無法在本地服務器中使用Symfony2會話。我得到一個「通知:會話已經開始 - 忽略session_start()」錯誤。Symfony2會話已經開始 - 忽略session_start()

相同的腳本在我的生產服務器上正常工作。

我在Windows 7上通過PHP 5.3.5使用Xampp。會話auto_start在php.ini中關閉。

任何提示都會有幫助。由於

回答

12

我想這是一個咬晚,但如果它能夠幫助:

確保您session.autostart是(0)在php.ini

使用中的Symfony會話的方式關閉2從CONTROLER是以下情況:

$session = $this->getRequest()->getSession(); 

// store an attribute for reuse during a later user request 
$session->set('foo', 'bar'); 

// in another controller for another request 
$foo = $session->get('foo'); 

// use a default value if the key doesn't exist 
$filters = $session->get('filters', array()); 

http://symfony.com/doc/current/book/controller.html#managing-the-session

或從視圖:

{{ app.session.get('foo') }} 

你也應該調用start()即使當你讀/寫會話數據(因爲它建議和的getId()不會調用它爲例)時,自動調用

$session->start(); 
$id = $session->getId(); 

http://symfony.com/doc/master/components/http_foundation/sessions.html

您可能無法在生產服務器上收到錯誤的原因是因爲它的優先級僅限於「通知」。

相關問題