我想创建一个表单来编辑我的用户。与ManyToMany相关的用户和角色。在 UserUsers 实体中,我有一个 $roles 变量,它是ArrayCollection
:
public function __construct()
{
$this->roles = new ArrayCollection();
}
在我的表单上,我想通过多个选择表单元素为我的用户添加角色。在我的用户表单中:
public function buildForm( FormBuilderInterface $builder, array $options ) {
$builder->add( 'username' )
->add( 'password', 'repeated', array(
'type' => 'password',
'mapped' => false,
'required' => false,
'first_options' => array(
'label' => 'Password' ),
'second_options' => array(
'label' => 'Repeat Password' ) ) )
->add( 'roles', 'choice', array(
'mapped' => false,
'multiple' => true ) );
}
现在我的多项选择是空的。
如果我将映射设置为 true,则会收到一条错误消息:
UserRoles 无法在...中转换为 int
我尝试了很多方法,但我无法正确解决这个问题。