RegistrationFormType::buildForm() not compatible

杀马特。学长 韩版系。学妹 提交于 2019-12-12 08:07:16

问题


I just upgrade my Symfony 2.0.12 project to 2.1. I also installed FosUserBundle, but when I run command

php composer.phar update

then composer output an error:

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

It' says something that my previous RegistrationFormType is not compatible with new Symfony 2.1 form interface.

My composer.json

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

My 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';
    }
}

Any idea what is wrong?


回答1:


Your buildFOrm Method uses the old schema.. this got changed:

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

also ensure you include the new one..

use Symfony\Component\Form\FormBuilderInterface; 


来源:https://stackoverflow.com/questions/12359307/registrationformtypebuildform-not-compatible

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!