2016-12-13 6 views
0

私はSymfonyを初めて使い、ユーザロールを選択する機能を持つ登録フォームを作成しようとしています。Symfony 3がCollectionType(FOSUserBundle)としてロール登録されています

私はこれを設定するには、公式ドキュメントを使用:http://symfony.com/doc/current/bundles/FOSUserBundle/overriding_forms.html

しかし、私は次のエラーました:私のRegistrationTypeがある this screen

を:

<?php 
 

 
namespace DevLeaguesBundle\Form; 
 

 
use Symfony\Component\Form\AbstractType; 
 
use Symfony\Component\Form\FormBuilderInterface; 
 
use Symfony\Component\Form\Extension\Core\Type\CollectionType; 
 

 
class RegistrationType extends AbstractType 
 
{ 
 
    public function buildForm(FormBuilderInterface $builder, array $options) 
 
    { 
 
\t \t $builder->add('roles', CollectionType::class, array(
 
        'type' => 'choice', 
 
        'options' => array(
 
         'choices' => array(
 
          'ROLE_ADMIN' => 'Admin', 
 
         ) 
 
        ) 
 
\t \t \t )); 
 
    } 
 

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

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

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

答えて

0

あなたはChoiceTypeフィールドを使用する必要がありますhttp://symfony.com/doc/current/reference/forms/types/choice.html

$builder->add('roles', ChoiceType::class, array(
         'choices' => array(
          'ROLE_ADMIN' => 'Admin', 
        ) 
        ) 
); 
+0

私はにこれ以前のバージョンを試してみましたが、今、私は新しいエラーを取得するので、私はどこか間違っている何かを持っている必要がありますようだ:注意:文字列変換 Thxをにアレイをとにかく –

+0

あなたはこの通知はここから来ていることを絶対によろしいですライン? –

+0

今のところこのコードはコメントされており、どこにもバグはありません。あなたはそれが何から来ると思いますか? –

関連する問題