FormType复制表单字段“name”冲突 [英] FormType duplicate formfield "name" conflict

查看:145
本文介绍了FormType复制表单字段“name”冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的GameType.php文件中声明的不同表中有两个同名的属性。



但这些值与表列不同.name和Type.name来自不同的表。



我怎样才能在没有冲突的情况下显示它们两个?



$ p
$ b $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ {
$ builder
- > add('name',TextType :: class,[$ b $'class'=>'AppBundle:Game',
'choice_label'= >'name',
]);
$ builder
- > add('name',EntityType :: class,[
'class'=&'; AppBundle:Type',
'choice_label'=> ;'name',
'multiple'=> false,
'expanded'=> false
]);

$ / code>

它们都被称为'name',它导致Type的选择框覆盖游戏的TextField。
我调用了这个小部件,但这不起作用,因为它们都被称为'name':
$ b

  {{form_widget( form.name)}} 


解决方案

更改实体中的属性名称?如果您需要,您可以在视图中将它们标记为相同。


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) }}

解决方案

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 .

这篇关于FormType复制表单字段“name”冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆