lor*_*cso 3 forms entity arraycollection multipleselection symfony
我想创建一个表单来编辑我的用户.用户和角色与ManyToMany连接.在UserUsers实体中,我有一个$ roles变量,它是ArrayCollection
:
public function __construct()
{
$this->roles = new ArrayCollection();
}
Run Code Online (Sandbox Code Playgroud)
在我的表单上,我想通过多个select表单元素向我的用户添加角色.在我的用户表格中:
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 ) );
}
Run Code Online (Sandbox Code Playgroud)
现在我的多重选择是空的.
如果我将map映射为true,我收到一条错误消息:
UserRoles无法在...中转换为int
我尝试了很多方法,但我无法正确解决这个问题.