我在我的实体中找到(使用findOneBy
)一个单行。这是代码:
$userown = $this->getDoctrine()->getRepository('GameShelfUsersBundle:Own')
->findOneBy(array(
'game' => $game->getId(),
'user' => $em->getRepository('GameShelfUsersBundle:User')->find($session->getId())
));
现在我将其作为userown
传递给模板。但是当我尝试使用{{ userown.typo }}
在树枝上打印时,会抛出错误:
An exception has been thrown during the rendering of a template ("Catchable Fatal Error: Object of class Proxies\__CG__\GameShelf\UsersBundle\Entity\OwnState could not be converted to string in D:\!!XAMPP\htdocs\
我的实体是here。
答案 0 :(得分:5)
Doctrine会自动解析您的外键,因此$typo
不是字符串而是对象。正如错误消息所示,此对象无法转换为字符串,因此打印失败。
您可以在__toString()
实体中实现OwnState
方法(它应该返回一个字符串),也可以打印OwnState对象的实际属性:{{ userown.type.someProperty }}
。
答案 1 :(得分:1)
你确定这是正确的
'game' => $game->getId()
我认为它应该是游戏对象本身而不是id
'game' => $game,