嵌入式实体作为symfony2形式的集合

时间:2014-08-01 10:02:44

标签: symfony

我有一张用户表 id|email|... 1|example@example.com
用户的动态字段表'最喜欢' id|name 1|juice 2|book etc
和3表'favorite_user'存储表2的参数
id|user|field|note 1| 1| 1|orage 2| 1| 2|classic
必须创建包含2个表中的所有字段的表单和2个表的每个值的3个表的输入字段“note”,但通过formbilder实体集合实现它不会显示任何内容 favorite_user的代码表单:

$builder
            ->add('favorite', 'collection',
                    array(
                'type' => 'Acme\DemoBundle\Form\Type\FavoriteFormType',
            ))
            ->add('note')
            ->add('button', 'submit');

收藏夹代码

$builder
            ->add('favorite', 'entity',
                    array(
                'class' => 'Acme\DemoBundle\Entity\Favorite',
                'property' => 'name'
    ));

显示

<div id="favoriteUser" class="form-control"></div>

但需要输入果汁,输入书籍。怎么做?

1 个答案:

答案 0 :(得分:0)

  $builder
        ->add('favorite', 'collection', array(
            'type' => //you have to specify the favorite form type here not an entity,
        ))

查看文档:{​​{3}}

这正是您要实现的目标:http://symfony.com/doc/current/reference/forms/types/collection.html#type

相关问题