【发布时间】:2015-04-23 21:32:08
【问题描述】:
我试过这样做:
$session->remove();
还有这个:
$session->clear();
但它给出了以下错误:
在非对象上调用成员函数 clear()
【问题讨论】:
我试过这样做:
$session->remove();
还有这个:
$session->clear();
但它给出了以下错误:
在非对象上调用成员函数 clear()
【问题讨论】:
无效()
清除所有会话数据并重新生成会话 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.
}
【讨论】:
Session对象的方法,而不是Controller。首先你必须访问Session 对象。请参阅我编辑的答案。