CollectionType et valeur par défaut de la BDD
Bonjour,
un autre soucis que je viens de voir. Quand je fait une collexion je n'ai pas le select avec la value de la BDD.
Je fais comme cela :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| class LeadsType extends AbstractType {
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options) {
$builder
->add('leadsActionsAssociations', CollectionType::class, array(
'entry_type' => ActionsType::class,
'allow_add' => true,
'allow_delete' => true,
'prototype' => true,
'by_reference' => false,
'attr' => array(
'class' => 'actions-list',
),
)
)
;
}
} |
Puis dans Actions :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| class ActionsType extends AbstractType {
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options) {
$builder
//->add('action', TextType::class)
->add('dateLimit', DateTimeType::class, array(
// render as a single text box
'widget' => 'single_text',
'html5' => false,
'format' => 'dd/MM/yyyy',
))
->add('commentaire', TextType::class)
->add('statutId', StatutActionsType::class)
->add('typeactionId', TypeActionsType::class)
->add('clientId', ClientType::class);
}
} |
Et puis par exemple dans TypeActionsType :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| class TypeActionsType extends AbstractType
{
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('libelle', EntityType::class, array(
'class' => 'BackBundle:TypeActions',
'query_builder' => function (TypeActionsRepository $er) {
return $er->createQueryBuilder('ta')
->orderBy('ta.libelle', 'ASC');
},
'choice_label' => 'libelle',
));
}
} |
Pourquoi je n'ai pas la valeur selectionné de la BDD ?
Si je met :
Code:
1 2 3 4 5 6 7 8
| ->add('libelle', EntityType::class, array(
'class' => 'BackBundle:TypeActions',
'query_builder' => function (TypeActionsRepository $er) {
return $er->createQueryBuilder('ta')
->orderBy('ta.libelle', 'ASC');
},
'choice_label' => 'libelle',
)); |
de la classe TypeActionsType directement dans ActionsType cela fonctionne....
Pourquoi et comment faire ?
Merci