Remove / Replace the username field with email using FOSUserBundle in Symfony2 / Symfony3

前端 未结 8 800
半阙折子戏
半阙折子戏 2020-12-02 05:06

I only want to have email as mode of login, I don\'t want to have username. Is it possible with symfony2/symfony3 and FOSUserbundle?

I read here http://groups.google

8条回答
  •  星月不相逢
    2020-12-02 05:32

    I was able to do this by overriding both the registration and profile form type detailed here and removing the username field

    $builder->remove('username');
    

    Along with overriding the setEmail method in my concrete user class:

     public function setEmail($email) 
     {
        $email = is_null($email) ? '' : $email;
        parent::setEmail($email);
        $this->setUsername($email);
      }
    

提交回复
热议问题