symfony2 many-to-many form checkbox

I've used entity type instead of collection. I thing collection is mainly used to actually create a Role object and assign it to User.

If you want to just list all existing roles and be able to select and assign it to the user then:

->add('roles', 'entity', array(
    'class' => 'MyBundle:Role',
    'property'     => 'name',
    'multiple'     => true
));

EDIT: this will render the widget as a multiple <select>, refer to entity type to render as checkbox list.


Symfony3:

In case anyone is using Symfony3:

use Symfony\Bridge\Doctrine\Form\Type\EntityType;

->add('roles', EntityType::class, array( // <-- EntityType::class is unique to Symfony3
    'class' => 'AppBundle:Role',
    'choice_label' => 'name', // <-- choice_label is unique to Symfony3
    'multiple' => true
))