作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我刚刚将我的 Symfony 2.0.12 项目升级到 2.1。我还安装了 FosUserBundle,但是当我运行命令
php composer.phar update
然后composer输出一个错误:
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';
}
}
知道出了什么问题吗?
最佳答案
您的 buildFOrm 方法使用旧架构。这已更改:
public function buildForm(FormBuilderInterface $builder, array $options)
还要确保包含新的..
use Symfony\Component\Form\FormBuilderInterface;
关于forms - RegistrationFormType::buildForm() 不兼容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12359307/
我刚刚将我的 Symfony 2.0.12 项目升级到 2.1。我还安装了 FosUserBundle,但是当我运行命令 php composer.phar update 然后composer输出一个
我是一名优秀的程序员,十分优秀!