dongxian7194 2011-12-01 16:27 采纳率: 0%
浏览 26

使用带有Doctrine记录的Twig时出错

I am trying to use Twig templates to display some objects fetched with Doctrine 1. I face an issue when accessing a relation declared with hasMany in the setUp function of the User class. In my PHP code I can do a $user->Instance without any issue but if I pass $user to the template and try to do a user.Instance an exception is raised:

Doctrine_Record_Exception' with message 'Unknown method User::Instance'

How can I solve this?

Thanks,

PS: using user.get('Instance') seems to work though I would of course prefer to avoid it

  • 写回答

1条回答 默认 最新

  • dongyao2001 2012-07-08 16:25
    关注

    To avoid this you have to define all the getters you want to call in the template because doctrine uses "magic methods" (__call()-method) to provide you the getters and setters.

    E.g. for property "firstname":

    Twig checks whether the method "getFirstname" exists but there is no method "getFirstname" defined in your model.

    Here you find a patch to tell doctrine to genrate the getters and setters: http://coolsoft.altervista.org/en/blog/2009/03/how-make-symfonydoctrine-generate-accessors

    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?