8

我只是将我的 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';
    }
}

知道有什么问题吗?

4

1 回答 1

19

您的 buildFOrm 方法使用旧模式.. 这已更改:

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

还要确保你包括新的..

use Symfony\Component\Form\FormBuilderInterface; 
于 2012-09-10T22:07:08.193 回答