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');

 

posted @ 2018-07-15 13:00  jyLi  阅读(265)  评论(0编辑  收藏  举报