Php Symfony,具有来自不同实体的字段的表单

Php Symfony,具有来自不同实体的字段的表单,php,symfony,Php,Symfony,我正在尝试使用2个不同的实体创建一个带有Symfony的表单 我想显示实体“候选对象”中的字段 以及实体“应用程序”中的字段 我确实很好地创建了“应用程序”字段,但当我尝试为“候选对象”添加新字段时,我遇到了一个错误: 试图调用类的名为“createView”的未定义方法 “Symfony\Component\Form\FormBuilder” 我的AppController代码是: /** * @Route("/form", name="form&quo

我正在尝试使用2个不同的实体创建一个带有Symfony的表单

我想显示实体“候选对象”中的字段 以及实体“应用程序”中的字段

我确实很好地创建了“应用程序”字段,但当我尝试为“候选对象”添加新字段时,我遇到了一个错误:

试图调用类的名为“createView”的未定义方法 “Symfony\Component\Form\FormBuilder”

我的AppController代码是:

/**
     * @Route("/form", name="form")
     */
    public function formulaire()
    {
        $application = new Applications();
        $candidat = new Candidats();

        $formCandidat = $this->createFormBuilder($candidat)
                            ->add("nom")
                            ->add("prenom")
                            ->add("email");

        $form = $this->createFormBuilder($application)
                    ->add("poste", ChoiceType::class, [
                        'choices'  => [
                        'Choisissez un poste ...' => null,
                        'Chef de Projet' => 'Chef de Projet',
                        'Secrétaire' => 'Secrétaire',
                        'Assistant' => 'Assistant',
                        ],
                    ])
                    ->add('pdf', FileType::class, [
                        'label' => 'Fiche de candidature (PDF)',
        
                        // unmapped means that this field is not associated to any entity property
                        'mapped' => false,
        
                        // make it optional so you don't have to re-upload the PDF file
                        // every time you edit the Product details
                        'required' => false,

                        'constraints' => [
                            new File([
                                'maxSize' => '1024k',
                                'mimeTypes' => [
                                    'application/pdf',
                                    'application/x-pdf',
                                ],
                                'mimeTypesMessage' => 'Please upload a valid PDF document',
                            ])
                        ]
                    ])
                    ->getForm();

        return $this->render('app/form.html.twig', [
            
            'form' => $form->createView(),
            'formCandidat' => $formCandidat->createView(),
        
            
        ]);
    }
   
}
我可能完全错了,我是怎么做的


有人知道我如何解决这个问题吗?

错误是由这行代码触发的

'formCandidat' => $formCandidat->createView(),
您没有为$FormCandidate调用getForm(),因此它仍然是FormBuilder对象

改变这个

$formCandidat = $this->createFormBuilder($candidat)
                    ->add("nom")
                    ->add("prenom")
                    ->add("email");
对此

$formCandidat = $this->createFormBuilder($candidat)
                    ->add("nom")
                    ->add("prenom")
                    ->add("email")
                    ->getForm();