简体   繁体   English

Symfony 3注册,角色为CollectionType(FOSUserBundle)

[英]Symfony 3 register with roles as CollectionType (FOSUserBundle)

I'm new to Symfony and I am trying to create a registration form with the capability to choose a user role. 我是Symfony的新手,我正在尝试创建一个具有选择用户角色功能的注册表单。

I used the official documentation to set this up: http://symfony.com/doc/current/bundles/FOSUserBundle/overriding_forms.html 我使用官方文档进行了设置: http : //symfony.com/doc/current/bundles/FOSUserBundle/overriding_forms.html

But I got the following error: 但我收到以下错误: 这个屏幕

My RegistrationType is : 我的RegistrationType是:

 <?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) { $builder->add('roles', CollectionType::class, array( 'type' => 'choice', 'options' => array( 'choices' => array( 'ROLE_ADMIN' => 'Admin', ) ) )); } public function getParent() { return 'FOS\\UserBundle\\Form\\Type\\RegistrationFormType'; } public function getBlockPrefix() { return 'devleagues_user_registration'; } public function getName() { return $this->getBlockPrefix(); } } 

You should use ChoiceType Field http://symfony.com/doc/current/reference/forms/types/choice.html 您应该使用ChoiceType字段http://symfony.com/doc/current/reference/forms/types/choice.html

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM