Symfony2:在非对象上调用成员函数getId(),即使存在对象?

Symfony2:在非对象上调用成员函数getId(),即使存在对象?,symfony,doctrine,Symfony,Doctrine,我不断地发现这个错误: /* ... */ $em = $this->getDoctrine()->getEntityManager(); $movie = $em->getRepository('MyMyBundle:Movie')->findMovieByName('moviename'); // Repository Class \Doctrine\Common\Util\Debug::dump($movie); // dumps t

我不断地发现这个错误:

    /* ... */
    $em = $this->getDoctrine()->getEntityManager();
    $movie = $em->getRepository('MyMyBundle:Movie')->findMovieByName('moviename'); // Repository Class
    \Doctrine\Common\Util\Debug::dump($movie); // dumps the object just fine! The Repository found it
    echo $movie->getId(); // brings me the error nevertheless
致命错误:对中的非对象调用成员函数getId()。。。在线

我的实体中有getId()方法。其他方法也不起作用,即使它和object

对象将被转储,如下所示:

..... array(1) { [0]=> object(stdClass)#759 (59) { ["__CLASS__"]=> string( .....

有什么提示吗?

没关系,我找到了答案:
echo$movie[0]->getId()(存储库返回了一个对象数组)。很抱歉,有时您会看不见树木的树木。

您使用的是自定义实体存储库吗?如果是,请发布
findMovieByName
方法。谢谢gilden。是的,它是一个自定义实体存储库。但我找到了答案(现在花了我大约一个小时)谢谢为了稍微简化代码,应该在存储库中使用Query::getSingleResult或Query::getOneOrNullResult方法。它们各自返回一个结果,如果有多个结果可用,则引发异常。此外,如果没有可用的结果,getSingleResult会引发异常。