validation - 如何覆盖 FOSUserBundle 的验证规则

标签 validation symfony symfony-forms fosuserbundle

我的ExampleUserBundle扩展了FOSUserBundle。我像这样重写 RegistrationFormType :

<?php
// Example/UserBundle/Form/Type/RegistrationFormType.php

namespace Example\UserBundle\Form\Type;

use Symfony\Component\Form\FormBuilderInterface;
use FOS\UserBundle\Form\Type\RegistrationFormType as BaseType;

class RegistrationFormType extends BaseType
{

    public function buildForm(FormBuilderInterface $builder, array $options) {
        parent::buildForm($builder, $options);
        $builder->remove('username');
    }

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

}

服务声明:

// Example/UserBundle/Ressources/Config/services.yml
services:
    example_user.registration.form.type:
        class: Example\UserBundle\Form\Type\RegistrationFormType
        arguments: [%fos_user.model.user.class%]
        tags:
            - { name: form.type, alias: example_user_registration }

在/app/config/config.yml 中:

fos_user:
    db_driver: orm
    firewall_name: main
    user_class: Example\UserBundle\Entity\User
    registration:
        form:
            type: example_user_registration

当我使用此表单创建新的User 时,FOSUserBundle 的基本验证规则不会覆盖。 (电子邮件 -> 唯一;密码 -> 超过 3 个字符;...)。

最佳答案

基本的解决方案是为注册表指定不同的验证组。

该解决方案对我有用:Validation of a form - I'm getting the labels two times

关于validation - 如何覆盖 FOSUserBundle 的验证规则,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19183538/

相关文章:

php - Symfony2 和 Twig 在 vagrant box 中的表现

forms - Controller Action 中的symfony2 : setting the value of a form field outside the form,

symfony1 - Symfony 1.4 表单模板

php - 使用 jquery 和 php 测试表单输入是否为 1 或 2 位整数

java - Spring 框架的验证无法与 JSR-303 验证一起使用

ruby-on-rails - Rails : validate presence of foo unless bar == 'baz'

php-cs-修复程序 : need more information on using fix --level option

mysql - 教义得到结果问题

unit-testing - Symfony2 最佳实践、业务逻辑和单元测试

python - 在模型级别将 Django DateField 验证为一周中的特定日期的最佳做法是什么?