drbz99867 2016-06-22 11:02
浏览 24
已采纳

Symfony 3 - 结束表单块的最佳实践

I'm trying to learn how to build forms in symfony 3. Following some tutorials I have built a PersonType

class PersonType extends AbstractType {

    public function buildForm(FormBuilderInterface $builder, array $options) {

        $builder->add('gender', ChoiceType::class, array('label' => 'Anrede', 'choices' => array('Herr' => 'Herr', 'Frau' => 'Frau'), 'attr' => array('class' => 'form-control')))
                ->add('title', TextType::class, array('label' => 'Titel', 'attr' => array('class' => 'form-control')))
                ->add('firstname', TextType::class, array('label' => 'Vorname', 'attr' => array('class' => 'form-control')))
                ->add('lastname', TextType::class, array('label' => 'Nachname', 'attr' => array('class' => 'form-control')))
                ->add('birthdate', DateType::class, array('label' => 'Geburtsdatum', 'attr' => array('class' => 'form-control')))

                ->add('street', TextType::class, array('label' => 'Straße', 'attr' => array('class' => 'form-control')))
                ->add('streetnumber', TextType::class, array('label' => 'Hausnummer', 'attr' => array('class' => 'form-control')))
                ->add('zip', TextType::class, array('label' => 'PLZ', 'attr' => array('class' => 'form-control')))
                ->add('city', TextType::class, array('label' => 'Stadt', 'attr' => array('class' => 'form-control')))

                ->add('email', TextType::class, array('label' => 'E-Mail', 'attr' => array('class' => 'form-control')));        
        }

    public function getName() {
        return 'person';
        }       

    }

And some other types.

In the controller I have

$person = new Person();
$form = $this->createForm(PersonType::class, $person);

My question now is, how do I now concat the PersonType to some other Types to get one Form out of it? And how do I then set the submit-button?

  • 写回答

2条回答 默认 最新

  • dqjo4340 2016-06-22 11:10
    关注

    You cannot concatenate but you can include a subset of fields in several forms.

    Here you have a nice example in the Symfony documentation :

    http://symfony.com/doc/current/cookbook/form/inherit_data_option.html

    Recap :

    • Create a form with your subfields, with the option 'inherit_data' => true.
    • Use it in another form as field.
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来