我正在尝试自定义FOSUserBundle的默认/注册。 我想用单选按钮添加角色,而不是复选框按钮,但是当我将多个设置为错误时会出错。
我按照symfony文档:https://symfony.com/doc/current/reference/forms/types/choice.html
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\FormBuilderInterface;
use FOS\UserBundle\Form\Type\RegistrationFormType as BaseRegistrationFormType;
class RegistrationFormType extends AbstractType
{
public function getParent()
{
return BaseRegistrationFormType::class;
}
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('firstname')
->add('lastname')
->add('roles', ChoiceType::class, array(
'choices' => array(
'Owner' => 'ROLE_OWNER',
'Salesman' => 'ROLE_SALESMAN'
),
'expanded'=> true,
'multiple' => false,
'required' => true
));
}
}
错误: 注意:数组到字符串转换 500内部服务器错误 - ContextErrorException
跟踪:
[1] Symfony\Component\Debug\Exception\ContextErrorException: Notice: Array to string conversion
at n/a
in /home/amaury/PhpstormProjects/backend/vendor/symfony/symfony/src/Symfony/Component/Form/ChoiceList/ArrayChoiceList.php line 73
at Symfony\Component\Form\ChoiceList\ArrayChoiceList->Symfony\Component\Form\ChoiceList\{closure}(array())
in line
at call_user_func(object(Closure), array())
in /home/amaury/PhpstormProjects/backend/vendor/symfony/symfony/src/Symfony/Component/Form/ChoiceList/ArrayChoiceList.php line 158
at Symfony\Component\Form\ChoiceList\ArrayChoiceList->getValuesForChoices(array(array()))
in /home/amaury/PhpstormProjects/backend/vendor/symfony/symfony/src/Symfony/Component/Form/Extension/Core/DataTransformer/ChoiceToValueTransformer.php line 37
at Symfony\Component\Form\Extension\Core\DataTransformer\ChoiceToValueTransformer->transform(array())
in /home/amaury/PhpstormProjects/backend/vendor/symfony/symfony/src/Symfony/Component/Form/Form.php line 1106
at Symfony\Component\Form\Form->normToView(array())
in /home/amaury/PhpstormProjects/backend/vendor/symfony/symfony/src/Symfony/Component/Form/Form.php line 352
at Symfony\Component\Form\Form->setData(array())
in /home/amaury/PhpstormProjects/backend/vendor/symfony/symfony/src/Symfony/Component/Form/Extension/Core/DataMapper/PropertyPathMapper.php line 57
at Symfony\Component\Form\Extension\Core\DataMapper\PropertyPathMapper->mapDataToForms(object(User), object(RecursiveIteratorIterator))
in /home/amaury/PhpstormProjects/backend/vendor/symfony/symfony/src/Symfony/Component/Form/Form.php line 385
at Symfony\Component\Form\Form->setData(object(User))
in /home/amaury/PhpstormProjects/backend/vendor/friendsofsymfony/user-bundle/Controller/RegistrationController.php line 62
at FOS\UserBundle\Controller\RegistrationController->registerAction(object(Request))
in line
at call_user_func_array(array(object(RegistrationController), 'registerAction'), array(object(Request)))
in /home/amaury/PhpstormProjects/backend/var/cache/dev/classes.php line 4245
at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), 1)
in /home/amaury/PhpstormProjects/backend/var/cache/dev/classes.php line 4200
at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), 1, true)
in /home/amaury/PhpstormProjects/backend/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php line 168
at Symfony\Component\HttpKernel\Kernel->handle(object(Request))
in /home/amaury/PhpstormProjects/backend/web/app_dev.php line 28
at require('/home/amaury/PhpstormProjects/backend/web/app_dev.php')
in /home/amaury/PhpstormProjects/backend/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Resources/config/router_dev.php line 40
500 @ fos_user_registration_register
119 ms
11.1 MB
1
test
6
谢谢!