I would like to create a form to edit my users.
Users and roles connected with ManyToMany.
In UserUsers entity I have a $roles variable which is ArrayCollection:
public function __construct()
{
$this->roles = new ArrayCollection();
}
On my form I would like to add roles to my users via multiple select form element. In my user form:
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 ) );
}
Now my multiple select is empty.
If I turn mapped to true, I got an error message:
UserRoles could not be converted to int in...
I've tried a lots of ways, but I could not solve this problem correctly.
$builder->add( 'roles', 'entity', array( 'class' => 'AcmeUserBundle:UserRoles', 'multiple' => true, 'property' => 'name' ) );Then I got an error message: Expected argument of type "Doctrine\Common\Collections\Collection", "array" given