Symfony2:调用非对象的成员函数getId(),即使有一个对象? [英] Symfony2: Call to a member function getId() on a non-object even though there is an object?

查看:121
本文介绍了Symfony2:调用非对象的成员函数getId(),即使有一个对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不断得到这个错误:

    /* ... */
    $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() - 在...上的对象...

Fatal error: Call to a member function getId() on a non-object in ... on line ...

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

I have the getId() method in my Entity. Other methods also don't work even though it is and object!

该对象被转储为: / p>

The object gets dumped like:

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

任何提示?

推荐答案

Nevermind,我找到答案: echo $ movie [0] - > getId(); 返回一系列物体)对不起,有时你会看不到树木的木头。

Nevermind, I found the answer: echo $movie[0]->getId(); (the repository returned an array of objects). Sorry, sometimes you lose sight of the wood for the trees.

这篇关于Symfony2:调用非对象的成员函数getId(),即使有一个对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆