Symfony2:FOSUserBundle删除配置文件中的“编辑用户名”表单字段

时间:2014-02-20 14:04:41

标签: php symfony fosuserbundle

我正在尝试删除在FOSUserBundle中编辑用户名的选项。

我的ProfileFormType.php如下所示:

<?php

namespace ACME\MemberBundle\Form\Type;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Symfony\Component\Security\Core\Validator\Constraint\UserPassword as OldUserPassword;
use Symfony\Component\Security\Core\Validator\Constraints\UserPassword;

use FOS\UserBundle\Form\Type\ProfileFormType as BaseType;

class ProfileFormType extends BaseType {
    protected function buildUserForm(FormBuilderInterface $builder, array $options) {
        parent::buildUserForm($builder, $options);      
        $builder->remove('username');
    }

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

我还将其注册为服务并编辑了config.yml文件。但是,当我提交表单时,我收到以下警告消息:

  

此表单不应包含额外字段。

1 个答案:

答案 0 :(得分:2)

我自己找到了解决方案:

我还扩展了ProfileController我在POST请求中使用username参数的位置。由于现在缺少此参数,我收到了此消息。

相关问题