Doctrine ORM returning array [0] in find

3

I have a question .. I implemented Doctrine with Silex, I created the entity, the repository and the service, but at the time I do a search with findByEmail () for example, to display the result I have to use $ result [0] -> getNome () . Would there be any way to remove this [0] from find? my method You are like this:

public function fetchByEmail($email)
{
    $usuario = $this->em->getRepository($this->entity);

    return $usuario->findByEmail($email);

}

If you need more information just ask me .. Thankful

    
asked by anonymous 16.01.2017 / 22:25

1 answer

2

I was able to solve .. the problem is that the findBy of doctrine, returns an array with other arrays inside, there to return a single record I needed to use findOneBy ai solved my problem. Here is the code below:

public function fetchByEmail($email)
{
    $usuario = $this->em->getRepository($this->entity);

    return $usuario->findOneByEmail($email);

}
    
16.01.2017 / 23:02