简体   繁体   中英

How do I retrieve the underlying entity object from a Twig template in a Symfony2 entity field?

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?

I didn't understand well what you want to do exactly since you didn't provide any code but from what I understood you want to access the object of the child right?

If that's the case you can use child.get('value') and this will return the object

Which means you can call child.get('value').getDescription() or whatever function child object has

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM