2011-10-26 10 views
7

Symfony2 FOSUserBundleのRegistrationFormTypeをオーバーライドしようとしています。私はドキュメンテーションに従っており、すべてをカバーしていると信じています。私はFOSUserBundleへのオーバーライドを含むバンドルを作成しました。次のコードはこのバンドルとアプリケーションの設定です。FOSUserBundleフォームタイプのオーバーライド時にタイプ「XYZ」エラーをロードできませんでした

FOSUserBundleをオーバーライドするときにこれを経験したことがありますか、またはこのエラーが発生する理由を説明するのに役立つコード内のものを参照してください。 私はsymfonyのV2.0.4

fos_user: 
    ... 
    registration: 
     form: 
     type: thrive_user_registration 
+0

サービス定義で '%fos_user.model.user.class% 'の代わりにこのパラメータ'%fos_user.model.user.form_data_class% 'を使うのはどうですか? –

答えて

4

は私のservices.ymlファイルは、依存性注入を介してロードされていませんでしたが判明します。私は、このバンドルのextension.phpファイルの名前が間違っていたことに気付きました。 DependencyInjectionフォルダ内のextension.phpファイルの名前を変更すると、早い時期にバンドルの名前が変更され、タイプミスが発生しました。間違ったものを修正した後、すべてが再び動作します。

+0

パーフェクト、私のエクステンションファイルも見逃しました。 – jmoz

0

は、あなただけの1を追加しようとしたんでした

RegistrationFormType.php

<?php 

/* 
* This file is part of the FOSUserBundle package. 
* 
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/> 
* 
* For the full copyright and license information, please view the LICENSE 
* file that was distributed with this source code. 
*/ 

namespace Thrive\SaasBundle\Form\Type; 

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

class RegistrationFormType extends BaseType 
{ 

    public function buildForm(FormBuilder $builder, array $options) 
    { 
     $builder 
      ->add('firstname', null, array('error_bubbling' => true)) 
      ->add('lastname', null, array('error_bubbling' => true)) 
      ->add('company', null, array('error_bubbling' => true)) 
      ->add('email', 'email', array('error_bubbling' => true)) 
      ->add('username', null, array('error_bubbling' => true)) 
      ->add('plainPassword', 'repeated', array('type' => 'password', 'error_bubbling' => true)) 
      ; 
    } 

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

} 

Services.yml

services: 
    thrive_saas_registration.form.type: 
    class: Thrive\SaasBundle\Form\Type\RegistrationFormType 
    arguments: [%fos_user.model.user.class%] 
    tags: 
     - { name: form.type, alias: thrive_user_registration} 

アプリケーションの設定ファイルによ新しいフィールドとそれが動作するかどうか見て?

public function buildForm(FormBuilder $builder, array $options) 
{ 
    parent::buildForm($builder, $options); 

    // add your custom field 
    $builder->add('name'); 
} 

また、あなたがそこからテストしている場合は、あなたのprodキャッシュをクリアすることを忘れないでください...

+0

私は持っているし、それは助けていないようだ。私はSymfony \ Component \ Form \ AbstractTypeから拡張しようと試みました。 FOSのRegistrationFormTypeが使用するコンストラクタとgetDefaultOptionsロジックを追加します。これはそれを修正するようには思われませんでした。 – Jeremy

+0

とても奇妙に見えます。これが私に起こるとすれば、私はFOSUserBundleのドキュメンテーションに従って "そのまま"、次に必要な設定に向けて少し変更を加えようとします... – dlondero

+0

そうです、それは変です...私のコードをロールバックしようとしています。 FOSのカスタマイズがあるバンドルをもう一度実装してください。 – Jeremy

関連する問題