3

I have a form builder which creates a form with an 'entity' field type (let's call that entity MyBundle:MyEntity). MyEntity has a property entitled 'description'. In addition to the __tostring() method automatically called by Symfony2 that is used for the label of each radio button, I'd like to access the description property.

I've overridden the choice_widget block and attempted to get {{ child.vars.value }}, but that's just the ID of the entity rather than the object itself.

Does anyone know how to do this, or if it is even possible?

4

1 回答 1

1

我不太了解您到底想做什么,因为您没有提供任何代码,但据我了解,您想访问孩子的对象,对吗?

如果是这种情况,您可以使用 child.get('value') 这将返回对象

这意味着您可以调用 child.get('value').getDescription() 或子对象具有的任何功能

于 2012-07-01T17:11:00.500 回答