Forms symfony2中的简单形式

Forms symfony2中的简单形式,forms,symfony,Forms,Symfony,我对一个简单的表单有问题。我有一个名为JurisdictionUser()的类,我的类形式是JurisdictionUserNewType()。 如果我输入下一个代码,它的工作正常: $jurisdiction_user = new JurisdictionUser(); $form = $this->createFormBuilder($jurisdiction_user) ->add('name', 'text') ->add('email'

我对一个简单的表单有问题。我有一个名为JurisdictionUser()的类,我的类形式是JurisdictionUserNewType()。 如果我输入下一个代码,它的工作正常:

$jurisdiction_user = new JurisdictionUser();
$form = $this->createFormBuilder($jurisdiction_user)
        ->add('name', 'text')
        ->add('email', 'text', array('required' => false))
        ->add('save', 'submit')
        ->getForm();
但是,如果我输入下一个代码:

$jurisdiction_user = new JurisdictionUser();
$form = $this->createFormBuilder(new JurisdictionUserNewType(), $jurisdiction_user);
它给了我下一个错误:

ContextErrorException: Catchable Fatal Error: Argument 2 passed to Symfony\Bundle\FrameworkBundle\Controller\Controller::createFormBuilder() must be of the type array, object given, called in /home/sierra/dev_env/iyc-open010/src/Radmas/BackofficeAdminBundle/Controller/UserAdminController.php on line 119 and defined in /home/sierra/dev_env/iyc-open010/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Controller/Controller.php line 175
我需要帮助。我的类辖区UserNewType()

您应该使用

$this->createForm(new JurisdictionUserNewType(), $jurisdiction_user)
在控制器中,而不是createFormBuilder

$this->createForm(new JurisdictionUserNewType(), $jurisdiction_user)