FormType duplicate formfield “name” conflict

2019-09-19 23:45发布

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条回答
再贱就再见
2楼-- · 2019-09-20 00:06

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 .

查看更多
登录 后发表回答