我尝试这样做:
$session->remove();
还有这个:
$session->clear();
但是它给出了以下错误:
在非对象上调用成员函数clear()
invalidate()
清除所有会话数据并重新生成会话ID。不要使用session_destroy()。
这实际上是您想要的。
来源和更多信息:http : //symfony.com/doc/current/components/http_foundation/sessions.html
同样,只需查看源代码即可轻松检查此类情况。
对于这种情况,您应该检查Session
或SessionInterface
来源:
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.
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句