删除电子邮件字段FOSUserBundle

时间:2017-09-06 22:25:54

标签: symfony fosuserbundle

我需要从注册表中删除电子邮件字段 我的解决方案是覆盖注册FormType:

<?php
// src/AppBundle/Form/RegistrationType.php

namespace AppBundle\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;

class RegistrationType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder->remove('email');
    }

该文件已成功删除,但验证过程被解雇“请输入电子邮件”。
任何关于如何禁用电子邮件字段验证的想法,甚至是如何以正确的方式制作技巧。

2 个答案:

答案 0 :(得分:1)

您可以为其提供例如

的用户名值

user.php的

* @ORM\HasLifecycleCallbacks


/**
 *
 * @ORM\PrePersist()
 */
public function setEmailUser(){

    $this->email = $this->username;
}

答案 1 :(得分:1)

破解实体设置器:

public function setUsername($username) {
    $username = is_null($username) ? '' : $username;
    parent::setUsername($username);
    $this->setEmail($username);
    return $this;
}

从FormType中删除字段:

public function buildForm(FormBuilder $builder, array $options) {
    parent::buildForm($builder, $options);
    $builder->remove('email');
}
在破解它之前

但是,你应该从jolicode看看this presentation

如果您目前正在进行此类修改,那是因为FosUserBundle不适合您的项目。我认为你不应该使用它。 (Personnaly,我认为这不是一个好的捆绑,请阅读上面的完整演示文稿以表达自己的意见)

如果您想要替换它,我建议您使用此excellent tutorial来创建自己的安全系统。 (编码/粘贴/理解它的时间:2或3小时)

相关问题