Stevan Tosic Stevan Tosic - 1 year ago 162
PHP Question

Doctrine findBy() calling method from entity

I need little help to call method from entity.

Here is the code I had try to execute.

$datat = $this->getDoctrine()
->findBy(array('userId' => $userId));

after this, when I call


I get message about exeption "Error: Call to a member function getUser() on a non-object"

When I dump $data I got data from table or if I execute

with ID value.

Answer Source

findBy returns generally an ArrayCollection.

You should use findOneBy instead in order to target only one entity...

So :

$datat = $this->getDoctrine()  
   ->findOneBy(array('userId' => $userId));
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download