3
I have a question. I implemented Doctrine with Silex, created the entity, the Repository and the service, but when it comes to doing a search with findByEmail() for example, to display the result I have to use $result[0]->getNome(). Would there be any way to remove that [0] from find? my method is like this:
public function fetchByEmail($email)
{
$usuario = $this->em->getRepository($this->entity);
return $usuario->findByEmail($email);
}
If you need any more information, just ask me.. Grateful
public Function fetchByEmail($email) { $usuario = $this->em->getRepository($this->Entity); Return $usuario->findByEmail($email)[0]; }, would not solve your problem?
– Denis Rudnei de Souza
Thanks for the help Denis.. but is that there is no other way to do this without having to pass the [0] somewhere?
– Alexandro Zaleski
I’m researching, it’s actually know nothing about Doctrine, I replied in comment because I knew that the query response is an array, hence the need of [0]
– Denis Rudnei de Souza
Yes, tbm to all day searching.. I can’t find any reference.. but let’s continue, there must be some form.. and tbm am not very good with Doctrine.. to starting now...
– Alexandro Zaleski
could post findByEmail code?
– Denis Rudnei de Souza
This is a magical method of Doctrine.. I didn’t make it myself....
– Alexandro Zaleski
Let’s go continue this discussion in chat.
– Denis Rudnei de Souza
I managed to solve. the problem is that Doctrine findBy, returns an array with other arrays inside, then to return a single record I needed to use findOneBy there solved my problem.. Thanks Denis for the help..
– Alexandro Zaleski
You are welcome to create an answer to your own question and mark it as accepted to help other people who have the same problem
– Denis Rudnei de Souza