I\'m using entity choice list in my form. I want to use only specific entities (in example: only groups that user belongs to) So, in controller, I\'m getting these groups, a
If you want to use custom query, you have to set query_builder
option as follows:
use Doctrine\ORM\EntityRepository;
...
$message = new Message();
$form = $this->createFormBuilder($message)
->add('group', 'entity', array(
'class' => 'Vendor\MyBundle\Entity\Group',
'label'=>'Group:',
'query_builder' => function(EntityRepository $er) {
return $er->createQueryBuilder('g')
->... // whatever you want to do
}
))
->getForm();
You can find more info about query builder in Doctrine manual and about options for entity
in Symfony2 manual.