2017-02-04 4 views
1

私はDoctrineとFOSBundle 2.0を使ってSymfony3のアプリケーションを開発しています。登録フォームにフィールドを追加しようとすると「app_user_registration」タイプを読み込めませんでした

登録バーに2つのフィールドを追加しようとしています。ファーストネームファーストネームです。

I have found this tutorial on how do do precisely what I'm hoping、残念ながら最初の数ステップ(前処理)にした後、私はこのエラーを取得しています実現:

Could not load type "app_user_registration"

私が使用しているコードはexacly唯一の違いは、webisteからをコピーしています私のクラスは、この

<?php 
// src/AppBundle/Entity/User.php 

namespace AppBundle\Entity; 

use FOS\UserBundle\Model\User as BaseUser; 
use Doctrine\ORM\Mapping as ORM; 
use Symfony\Component\Validator\Constraints as Assert; 

/** 
* @ORM\Entity 
* @ORM\Table(name="fos_user") 
*/ 
class User extends BaseUser 
{ 
    /** 
    * @ORM\Id 
    * @ORM\Column(type="integer") 
    * @ORM\GeneratedValue(strategy="AUTO") 
    */ 
    protected $id; 

    /** @ORM\Column(type="integer") */ 
    protected $carma; 

    /** 
    * @ORM\Column(type="string", length=255) 
    * 
    * @Assert\NotBlank(message="Please enter your first name.", groups={"Registration", "Profile"}) 
    * @Assert\Length(
    *  min=3, 
    *  max=255, 
    *  minMessage="The name is too short.", 
    *  maxMessage="The name is too long.", 
    *  groups={"Registration", "Profile"} 
    *) 
    */ 
    protected $firstName; 

    /** 
    * @ORM\Column(type="string", length=255) 
    * 
    * @Assert\NotBlank(message="Please enter your first name.", groups={"Registration", "Profile"}) 
    * @Assert\Length(
    *  min=3, 
    *  max=255, 
    *  minMessage="The name is too short.", 
    *  maxMessage="The name is too long.", 
    *  groups={"Registration", "Profile"} 
    *) 
    */ 
    protected $lastName; 

同じ効果のように見えるということですが発生...「名前」

という名前の変数が存在するとき

私は最後の数時間を費やしています。

すべてが他の質問への答えとしての私の出力コードを示した2.0マスターバージョンのチュートリアルを使用する: 私が試したものがあります。

誰かが貧しい人々を助けることができますか?ここでさらにとして

は、私の他のファイルは、以下のとおりです。

//config.yml 
/*...*/ 
fos_user: 
    db_driver: orm 
    firewall_name: main 
    user_class: AppBundle\Entity\User 
    registration: 
     form: 
      type: AppBundle\Form\RegistrationType 

//services.yml 
services: 
    app.form.registration: 
     class: AppBundle\Form\RegistrationType 
     tags: 
      - { name: form.type, alias: app_user_registration } 

//RegistraionType.php 
<?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->add('firstName'); 
    } 

    public function getParent() 
    { 
     return 'fos_user_registration'; 
    } 

    public function getName() 
    { 
     return $this->getBlockPrefix(); 
    } 

    public function getBlockPrefix() 
    { 
     return 'app_user_registration'; 
    } 
} 
+0

このエラーは、お使いのUserエンティティではないが、そのアプリであなたが設定しているエイリアスを使用しようとしているから来ます/ config/services.ymlをあなたのユーザー登録フォームを参照してください。 – pogeybait

+0

また、エラーが発生している場所であるため、フォームタイプの処理も行いましたか。他の例を探すときは注意してください。投稿した2番目のリンクは、古いバージョンのFOSUserBundle用です。確かに、あなたが見つけるほとんどの例は時代遅れです。 – Cerad

答えて

0

私はあなたにも登録フォームを拡張するためのチュートリアルに従うことをしようとしている疑いがあります。次に、あなたのsrc/AppBundle /フォーム/ RegistrationType.phpに次のような機能を持っている必要があり

app.form.registration: 
    class: AppBundle\Form\RegistrationType 
    tags: 
     - { name: form.type, alias: app_user_registration } 

:あなたは、ほとんどの場合、あなたのアプリ/設定/ services.ymlファイルに次のエントリを持っている必要があり

public function getBlockPrefix() 
{ 
    return 'app_user_registration'; 
} 

これは、getBlockPrefix()メソッドでエラーが発生している可能性が最も高いです。あなたのservices.ymlをチェックし、私が投稿したものと比較してください。私はうまく動作している自分のアプリからそれをつかんだ。あなたはチュートリアル "の1.3.xバージョン" を使用している http://symfony.com/doc/master/bundles/FOSUserBundle/overriding_forms.html

+0

私は、 'FOS \ UserBundle \ Form \ Type \ RegistrationFormType'を返すべきときに' app_user_registration'を返したので、実際には 'getParent()'関数にありました。 – aln447

0

あなたはこのtuorial代わりに(2.0.master)を使用する必要があります。

Symfony3については

あなたがこれをしなければならないが、変更されます。

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

    public function getParent() 
    { 
     return 'FOS\UserBundle\Form\Type\RegistrationFormType'; 
    } 

    public function getBlockPrefix() 
    { 
     return 'app_user_registration'; 
    } 

}
 
services: 
    app.form.registration: 
     class: AppBundle\Form\RegistrationType 
     tags: 
      - { name: form.type, alias: app_user_registration } 
 
fos_user: 
    # ... 
    registration: 
     form: 
      type: AppBundle\Form\RegistrationType 
関連する問題