Reputation: 312
I'm trying to create a comment form, but I'm stuck with something.
I retrieve my data with findBy(array('slug' => $slug))
.
I know that this method returns an array, not an object. When I want to add a comment, I have an error
"Type error: Argument 1 passed to AppBundle\Entity\Comment::setTrick() must
be an instance of AppBundle\Entity\Trick, array given, called in
/Applications/MAMP/htdocs/SnowTricks/src/AppBundle/Controller
/AppController.php on line 71"
How can I create, or use a method that returns an object ?
Thanks for your replies and sorry for my English
Upvotes: 1
Views: 737
Reputation: 4244
If you need to retrieve single entity, you should use method ::findOneBy
$entity = $this->getDoctrine()
->getRepository('AppBundle:Trick')
->findOneBy(array('slug' => $slug))
;
Upvotes: 4