-->

RegistrationFormType :: buildForm()不兼容(Registratio

2019-07-31 11:52发布

我只是我的Symfony 2.0.12项目升级到2.1。 我也装FosUserBundle,但是当我运行命令

php composer.phar update

然后作曲家输出一个错误:

Loading composer repositories with package information
Updating dependencies
Writing lock file
Generating autoload files
PHP Fatal error:  Declaration of User\UserBundle\Form\Type\RegistrationFormType::buildForm() must be compatible with that of Symfony\Component\Form\FormTypeInterface::buildForm() in /home/mark/dev/proj/src/User/UserBundle/Form/Type/RegistrationFormType.php on line 38

Fatal error: Declaration of User\UserBundle\Form\Type\RegistrationFormType::buildForm() must be compatible with that of Symfony\Component\Form\FormTypeInterface::buildForm() in /home/mark/dev/proj/src/User/UserBundle/Form/Type/RegistrationFormType.php on line 38
Script Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache handling the post-update-cmd event terminated with an exception

它说的东西,我以前RegistrationFormType不符合新Symfony的2.1形式的接口兼容。

我composer.json

// ...
"friendsofsymfony/user-bundle": "*",
//...

我RegistrationFormType.php

<?php

namespace User\UserBundle\Form\Type;

use Symfony\Component\Form\FormBuilderInterface;
use FOS\UserBundle\Form\Type\RegistrationFormType as BaseType;

class RegistrationFormType extends BaseType
{
    public function buildForm(FormBuilder $builder, array $options)
    {
        parent::buildForm($builder, $options);
        // add your custom field
        $builder->add('name')
                ->add('surname')
                ->add('gender', 'choice', array(
                    'choices'   => array('m' => 'Male', 'f' => 'Female'),
                    'empty_value' => 'Please select',
                ))
                ->add('address')
                ->add('zip')
                ->add('country', 'country', array(
                    'empty_value' => 'Please select',
                ))
            ->add('dateOfBirth', 'date', array(
                'empty_value' => '',
                'years' => range(date('Y')-100, date('Y')),
            ))
            ->add('agree', 'checkbox', array(
                'label'     => 'Check here to agree to the sites terms and Conditions and Data Privacy Policy.',
            ));
    }

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

任何想法有什么不好?

Answer 1:

你buildFOrm方法中,使用旧模式..这得到了改变:

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

还确保您包括新的..

use Symfony\Component\Form\FormBuilderInterface; 


文章来源: RegistrationFormType::buildForm() not compatible