2013-10-04 171 views
1

我的ExampleUserBundle延伸FOSUserBundle。我重寫RegistrationFormType這樣的:如何覆蓋FOSUserBundle的驗證規則

<?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個字符; ...)。

回答