【问题标题】:Symfony2: FOSUserBundle remove "Edit Username" form field in profileSymfony2:FOSUserBundle 删除配置文件中的“编辑用户名”表单字段
【发布时间】:2014-02-20 14:04:41
【问题描述】:

我正在尝试删除在 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 文件。但是,当我提交表单时,我会收到以下警报消息:

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

【问题讨论】:

    标签: php symfony fosuserbundle


    【解决方案1】:

    我自己找到了解决方案:

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

    【讨论】:

    • sweet 我正在寻找一种从表单中删除用户名和密码编辑的好方法,有趣的是我没有在构建器中找到密码“添加”方法,我还检查了表单工厂在没有线索的情况下用于配置文件控制器,我不得不检查 html 并猜测名称“plainPassword”
    猜你喜欢
    • 2012-02-08
    • 2018-01-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-02
    • 2017-01-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多