symfony3常用记忆

1、控制器里获取当前用户信息

$user = $this->getUser();

2、判断当前用户是否登录

// yay! Use this to see if the user is logged in
if (!$this->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_FULLY')) {
    throw $this->createAccessDeniedException();
}
// equivalent shortcut:
// $this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');

// boo :(. Never check for the User object to see if they're logged in
if ($this->getUser()) {

}

3、控制器里面重定向

$this->redirectToRoute('homepage');

猜你喜欢

转载自www.cnblogs.com/linxingyun/p/9313285.html