Symfony2如何使用表单和实体类型

时间:2016-01-07 06:40:57

标签: php symfony symfony-forms symfony-2.8

我有三个表teamgroupsgroup_teamgrouponeToMany group_teamteamOneToOne group_team。一个团队可以拥有多个团队,一个团队只能属于一个团队。这是我的数据库设计

如何在数据库中同时创建oneToMany记录的同时,将组和团队的groups关系保持在第三个表中

enter image description here

这里是组实体表单类型

class GroupsType extends AbstractType {

    public function buildForm(FormBuilderInterface $builder, array $options) {
        $builder
                ->add('team', 'entity', array(
                                        'class' => 'CricketBundle\Model\Entity\Team',
                                        'query_builder' => function(\Doctrine\ORM\EntityRepository $er) {
                                                            return $er->createQueryBuilder('t')
                                                                      ->groupBy('t.team')
                                                                      ->orderBy('t.team', 'ASC');
                                                            }, 
                                        'choice_label' => 'team',
                                        'multiple'     => true,
                                        'expanded'     => true,
                                        'required' => false
                                    ))
                ->add('groupname')
        ;
    }

    public function configureOptions(OptionsResolver $resolver) { 
        $resolver->setDefaults(array(
            'data_class' => 'CricketBundle\Model\Entity\Groups'
        ));
    }
}

这里是组实体表单的呈现方式

enter image description here enter image description here

0 个答案:

没有答案