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

Mik*_*ike 4 doctrine symfony

我一直收到这个错误:

    /* ... */
    $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
Run Code Online (Sandbox Code Playgroud)

致命错误:在......在线的非对象上调用成员函数getId()...

我的实体中有getId()方法.其他方法即使它对象也不起作用!

对象被转储如下:

..... array(1) { [0]=> object(stdClass)#759 (59) { ["__CLASS__"]=> string( .....
Run Code Online (Sandbox Code Playgroud)

任何提示?

Mik*_*ike 11

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