FormType duplicate formfield “name” conflict

倖福魔咒の 提交于 2019-12-13 22:05:55

问题


I have two properties with the same name from different tables declared in my GameType.php file.

But these are actually not the same values as the table columns Game.name and Type.name come from different tables.

How can I display both of them in the form without conflicts?

Snippet from GameType.php:

public function buildForm(FormBuilderInterface $builder, array $options)
{
    $builder
        ->add( 'name', TextType::class, [
            'class' => 'AppBundle:Game',
            'choice_label' => 'name',
        ] );
    $builder
        ->add( 'name', EntityType::class, [
            'class' => 'AppBundle:Type',
            'choice_label' => 'name',
            'multiple' => false,
            'expanded' => false
        ] );
}

They're both called 'name' which causes the Type's selectbox to override the Game's TextField. I call the widget, but that's not working because they are both called 'name':

{{ form_widget(form.name) }}

回答1:


Why don't you change the properties name in the entity ? you can label them the same in the view after that if you need .



来源:https://stackoverflow.com/questions/42577817/formtype-duplicate-formfield-name-conflict

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!