1

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

1
  • 1
    Please show more of your AppController.php code. Especially around Line 71. Commented Aug 10, 2017 at 5:26

1 Answer 1

4

If you need to retrieve single entity, you should use method ::findOneBy

$entity = $this->getDoctrine()
    ->getRepository('AppBundle:Trick')
    ->findOneBy(array('slug' => $slug))
;
Sign up to request clarification or add additional context in comments.

1 Comment

It works very well, sorry for this, I should have checked the findOneBy method returns an object ...

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.