Search code examples
symfonydoctrine-ormfosuserbundlefindby

Symfony2 - FOSUserBundle - FindUserBy<field_in_custom_UserBundle>


I´ve created my own user Bundle, extending FOSUserBundle.

In my UserBundle, I have a memberID field, with its setters and getters.

I can already find users by memberID using EntityManager, and then I could find the user through UserManager matching the username/email/... obtained with that EntityManager query, but...

Is there a way to findUserByMemberID using UserManager?

Thank you.


Solution

  • Thank you for your replies. It seems it´s easier than all this stuff.

    OwnUserBundle:

     /**
     * @ORM\Column(type="string")
     *
     */
    protected $memberID;
    
    public function getMemberID()
    {
        return $this->memberID;
    }
    
    public function setMemberID($memberID)
    {
        $this->memberID = $memberID;
    }
    

    You can query FOSUserBundle:

    $userManager = $this->get('fos_user.user_manager');
    
    $user = $userManager->findUserBy(array('memberID' => '123'));
    

    Then, using method findUserBy(array(*OwnUserBundle_field* => *search_parameter_value*)) you´ll get the user/s instance.