2012-12-12 59 views
0

我想覆蓋FOSUserBundle的唯一原因,我可以把一個默認值,同時建立窗體,所以我沒有得到不適當的驗證消息在laoding窗體...Symfony2 FOSUserBundle覆蓋表單:無法加載類型錯誤

我在關注the doc。我已經把Etienne/UserBundle/Form/Type/RegistrationFormType.php

 <?php 


    namespace Etienne\UserBundle\Form\Type; 

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

    class RegistrationFormType extends BaseType 
    { 

public function buildForm(FormBuilderInterface $builder, array $options) 
{ 
    $builder 

     ->add('username', null, array('label' => 'form.username', 'translation_domain' => 'FOSUserBundle')) 
     ->add('email', 'email', array('label' => 'form.email', 'translation_domain' => 'FOSUserBundle')) 
     ->add('plainPassword', 'repeated', array(
      'type' => 'password', 
      'options' => array('translation_domain' => 'FOSUserBundle'), 
      'first_options' => array('label' => 'form.password'), 
      'second_options' => array('label' => 'form.password_confirmation'), 
      'invalid_message' => 'fos_user.password.mismatch', 
     )) 
    ; 
} 

public function setDefaultOptions(OptionsResolverInterface $resolver) 
{ 
    $resolver->setDefaults(array(
     'data_class' => $this->class, 
     'intention' => 'registration', 
    )); 
    } 

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

Etienne/UserBundle/Resources/config/services.yml

services: 
    etienne_user.registration.form.type: 
     class: Etienne\UserBundle\Form\Type\RegistrationFormType 
     arguments: [%fos_user.model.user.class%] 
     tags: 
     - { name: form.type, alias: etienne_user_registration } 

app/config

FOS_User 
    registration: 
     form: 
      type: etienne_user_registration 

我得到這個錯誤信息:

在/ var/WWW/projet_etienne_auth /供應商/ symfo NY/symfony中/ src目錄/ Symfony的/分量/表格/ FormRegistry.php在95行

 if (!$type) { 
      throw new FormException(sprintf('Could not load type "%s"', $name)); 
     } 
     $this->resolveAndAddType($type); 

回答

3

的問題是,我沒有在我的依賴注入文件夾中的文件EtienneUserExtension.php(不正確的bundle安裝)所以services.xml無法加載

1

在這一段代碼,你首先從的Symfony的Form成分導入BaseType類,後來與相同名稱來定義別名RegistrationFormTypeFOS

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

剛落,這個聲明(你不需要它),一切都應該罰款:

use Symfony\Component\Form\BaseType; 
+0

thanx,你是對的,但它不能解決文檔中的問題 – Matoeil

+0

它說它應該擴展baseType和我的默認FosSuser RegistrationFormType,它確實擴展AbstractType。 ..有什麼不同 兩者之間..我已經嘗試了無論如何 – Matoeil

+0

BaseType只是RegistrationFormType(在你的情況)的別名。它不是一個單獨的課程。 – ualinker

相關問題