我findOneBy在我的实体中找到(使用)一个单行.这是代码:
$userown = $this->getDoctrine()->getRepository('GameShelfUsersBundle:Own')
->findOneBy(array(
'game' => $game->getId(),
'user' => $em->getRepository('GameShelfUsersBundle:User')->find($session->getId())
));
Run Code Online (Sandbox Code Playgroud)
现在我将它传递给模板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\
Run Code Online (Sandbox Code Playgroud)
我的实体就在这里.
Doctrine会自动解析您的外键,因此$typo不是字符串而是对象.正如错误消息告诉您的那样,此对象无法转换为字符串,因此打印失败.
您可以__toString()在OwnStateEntity中实现该方法(它应该返回一个字符串),也可以打印OwnState对象的实际属性:{{ userown.type.someProperty }}.
| 归档时间: |
|
| 查看次数: |
3480 次 |
| 最近记录: |