在 Symfony 5 中使用 ChoiseType 的无效消息

问题描述

我在 Symfony 5 中创建了一个表单类型并在 $builder 中使用它:

    ->add(
        $builder
            ->create('roles',ChoiceType::class,[
                'choices' => [
                    'Admin' => 'ROLE_ADMIN','User' => 'ROLE_USER','Ban' => 'ROLE_BAN'
                ],'constraints' => [
                    new NotBlank([
                        'message' => 'Choose Role!'
                    ])
                ]
            ])
            ->addModelTransformer(new CallbackTransformer(
                function ($roles) {
                    // transform the array to a string
                    return $roles[0] ?? null;
                },function ($roles) {
                    // transform the string back to an array
                    return [$roles];
                }
            ))
    )

但是 NotBlank 不起作用!

我该如何解决这个问题?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)