Symfony2: How to get user Object inside controller when using FOSUserBundle?

后端 未结 8 1893
别跟我提以往
别跟我提以往 2020-12-28 13:04

I\'m using FOSUserBundle to authenticate my users.

I\'m trying to get the user object inside the Controller to register a trip where I should add the user object to

8条回答
  •  旧巷少年郎
    2020-12-28 13:24

    public function indexAction()
    {
        /* @var $user \FOS\UserBundle\Model\UserInterface */
        if ($user = $this->getUser())
        {
            echo '
    ';
            print_r($user);
            print_r($user->getRoles()); // method usage example
    
            exit;
    
            return $this->redirectToRoute('dashboard');
        }
    
        return $this->redirectToRoute('login');
    }
    

提交回复
热议问题