Symfony2:即使存在对象,也要在非对象上调用成员函数 getId()? [英] Symfony2: Call to a member function getId() on a non-object even though there is an object?

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

问题描述

我不断收到此错误:

    /* ... */
    $em = $this->getDoctrine()->getEntityManager();
    $movie = $em->getRepository('MyMyBundle:Movie')->findMovieByName('moviename'); // Repository Class
    DoctrineCommonUtilDebug::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() 方法.即使它和对象,其他方法也不起作用!

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

对象被转储如下:

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

有什么提示吗?

推荐答案

没关系,我找到了答案: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天全站免登陆