2015-04-23 112 views

回答

1

invalidate()

Clears all session data and regenerates session ID. Do not use session_destroy().

这其实你想要做什么。

来源&更多信息: http://symfony.com/doc/current/components/http_foundation/sessions.html

而且这样的事情很容易,只需查看源进行检查。

对于这种情况,你应该检查SessionSessionInterface来源:

http://api.symfony.com/2.6/Symfony/Component/HttpFoundation/Session/SessionInterface.html

http://api.symfony.com/2.6/Symfony/Component/HttpFoundation/Session/Session.html

编辑。

当然,这种方法属于Session类,因此您必须首先在控制器中访问Session对象。

所以我们去:

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

,我们看到如何做到这一点:

public function indexAction(Request $request) 
{ 
    $session = $request->getSession(); 

    $session->invalidate(); //here we can now clear the session. 
} 
+0

以下错误发生 尝试从命名空间“主页\ HomeBundle通话功能 “失效” \ Controller –

+0

这是'Session'对象的一种方法,而不是'Controller',首先你必须访问'Session'对象,看到我编辑的答案 –

+0

谢谢它解决了我的pr oblem :)一个更多的queastion ...现在我正在做这个动作开始会话 $ session = new Session(); $ this-> session-> start(); 我想写这个$ session = new Session();在构造函数中,并在控制器的所有操作中使用它。我怎么能做到这一点,我无法在任何地方找到它的语法。 –