Trier une collection de formulaire
Bonjour,
Existe-t-il une solution pour trier une collection de formulaire en fonction d'un champ.
J'ai un fomulaire ArchitectureType
Code:
1 2 3 4 5 6 7 8 9 10 11
|
//...
$builder
->add( 'batiments', 'collection', array(
'type' => new BatimentType(),
'allow_add' => true,
'allow_delete' => true,
'by_reference' => false,
'prototype' => true))
->getForm();
//... |
et un autre BatimentType
Code:
1 2 3 4 5 6 7
|
//...
$builder
->add('libelle', 'text')
->add('position', 'integer', array('required'=>false))
->getForm();
//... |
L'entité Architecture a une relation OneToMany définie comme ça :
Code:
1 2 3 4 5 6
|
/**
* @ORM\OneToMany(targetEntity="Acme\MyBundle\Entity\batiment", mappedBy="architecture", cascade={"persist", "remove"})
* @ORM\OrderBy({"position" = "ASC"})
*/
protected $batiments; |
Le template twig : {{ form }} est le formulaire ArchitectureType
Code:
1 2 3 4 5 6 7 8 9 10 11
|
<table id="batiments" class="w100p listview">
<tbody>
{% for batiment in form.batiments %}
<tr>
<td>{{ form_widget(batiment.libelle) }}</td>
<td>{{ form_widget(batiment.position) }}</td>
</tr>
{% endfor %}
</tbody>
</table> |
Comment faire pour afficher les champs de form.batiments dans l'ordre de batiment.position ?
Merci pour votre aide
Gillou.