[英]User doesn't logout properly in Symfony2
I'm trying to logout an user (session) when the Logout link is clicked. 单击注销链接时,我试图注销用户(会话)。 It seems to work when I pressed the Logout, but if I change the path, the user still alive and I don't know why.
当我按下Logout时,它似乎可以正常工作,但是如果我更改路径,则用户仍然有效,我也不知道为什么。
Here's my Controller
: 这是我的
Controller
:
/**
* @Route("/logout", name="logout")
*/
public function logoutAction(Request $request)
{
$helper = $this->get('security.authentication_utils');
$this->container->get('security.token_storage')->setToken(null);
$this->get('session')->set('id', null);
$request->getSession()->invalidate();
$this->get('security.token_storage')->setToken(null);
return $this->render(
'login.html.twig',
array(
'last_username' => null,
'error' => null,
)
);
}
Here's my security.yml: 这是我的security.yml:
security:
# ...
main:
anonymous: ~
guard:
authenticators:
- app.form_login_authenticator
logout:
path: logout
target: logout
invalidate_session: true
Here's the routing.yml: 这是routing.yml:
app:
resource: '@AppBundle/Controller/'
logout:
path: /logout
Remove the logoutAction
and check if it works. 删除
logoutAction
并检查其是否有效。 This action is provided by Symfony itself. 此操作由Symfony本身提供。 You should only set logout path in
security.yml
what you did. 您只应该在
security.yml
设置注销路径。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.