Accéder aux champs d'un entity dans un form d'un autre entity
Bonjour,
J'ai une entity "Site" qui contient un certain nombre de champs dont 1 qui est une relation ManyToOne vers une autre entity qui est Hospital. Cette entity Hospital a plusieurs champ et notamment nom, address, ville...
Je crée un formulaire basé sur mon entity Site:
Code:
1 2 3 4 5 6 7 8 9
|
public function buildForm(FormBuilderInterface $builder, array $options)
{
parent::buildForm($builder, $options);
$builder->add('nom', 'text')
->add('institution', 'text')
->add('hospital', 'entity', array('class' => 'DataBaseBundle:Hospital'))
... |
Dans mon twig je veux afficher les infos de mon formulaire.
Donc je fais
Code:
1 2 3 4
|
{{ form_widget(monform.nom) }}
{{ form_widget(monform.institution) }}
{{ form_widget(monform.hospital) }} |
Pas de soucis ca marche bien (j'ai rajouté une méthode toString() dans la classe de l'entity Hospital.)
Maintenant je voudrais affiché les propriétés de mon entity hospital dans mon twig.
Comment je fais ?
J'ai essayé
Code:
{{ form_widget(monform.hospital.name) }}
Mais ça ne marche pas.
Merci de votre aide.