首页 > 解决方案 > 我希望我的 entityType 的每个选择都显示该选择的许多属性 Symfony 4

问题描述

这是我的问题,我正在使用 Symfony 4。我创建了一个表单并添加了另一个表单类型的集合。它工作得很好,但现在,我想将 Collection 更改为 EntityType。

这是我的第一个代码

$builder
    ->add('id_etudiant', EtudiantSecondType::class)
    ->add('id_diplome', DiplomeType::class)
    ->add('suivres', CollectionType::class, [
        'entry_type' => SuivreType::class,
        'entry_options' => ['label' => false],
    ]) ;

现在我想把它改成这样

$builder
    ->add('id_etudiant', EtudiantSecondType::class)
    ->add('id_diplome', DiplomeType::class)
    ->add('suivres', EntityType::class, [
        'class' =>SuivreType::class,
        'block_name'=>'app_one_module_type',
        'block_prefix'=>'app_one_module',
        'mapped'=>false,
        'expanded'=>true,
        'multiple'=>true,
        'choice_label'=>function(Suivre  $suivre){
            return "";
        },
    ])
;

我认为我们不能在 EntityType 中指定表单类型,所以我添加了我需要的树枝部分,但它不起作用。我得到了结果,但不是我声明的树枝格式:

'block_name'=>'app_one_module_type',
'block_prefix'=>'app_one_module',

标签: formssymfonytwigsymfony-formstwig-extension

解决方案


推荐阅读