我想在symfony 2中创建多个表单。这是正确的方法吗?

时间:2015-03-06 10:11:03

标签: php symfony doctrine symfony-forms

**这是我的控制器**

public function companyConfigAction(Request $ request){

    $form = array();    
    $addCompany = new CompanyAccount();
    $addBankDetails = new CompanyBankAccount();
    $addCompany->addBankDetails($addBankDetails);

    $addCompanyAccountForm = $this->createForm(new CompanyAccountType(), $addCompany);
    $addCompanyCommisionForm = $this->createForm(new CompanyBillingCommissionInfoType(), new CompanyBillingCommissionInfo());
    $companyContactInfo = new CompanyContactInfo();
    $addCompanyContactInfoForm = $this->createForm(new CompanyContactInfoType(), $companyContactInfo);
    $addCompanySubscriptionForm = $this->createForm(new CompanyOtherSubscriptionType(), new CompanyOtherSubscription());

    return $this->render('BillingInvoiceBundle:Company:configuration.html.twig', [
                'entity' => $addCompany,
                'companyAccountForm' => $addCompanyAccountForm->createView(),
                'companyCommissionForm' => $addCompanyCommisionForm->createView(),
                'companyContactInfo' => $addCompanyContactInfoForm->createView(),
                'companySubscription' => $addCompanySubscriptionForm->createView(),
    ]);
}

1 个答案:

答案 0 :(得分:0)

如果您想在单个表单中使用所有这些表单,请查看集合表单类型:

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