Ray Kootstra Ray Kootstra - 3 months ago
427 0

Example how to get a dropdown filled with data from an entity via the querybuilder.

PHP

Symfony2 form populate dropdown from querybuilder

$builder->add('eventType', 'entity', array(
            'class' => EventType::class,
            'query_builder' => function (EventTypeRepository $eventTypeRepository) {
                return $eventTypeRepository->createQueryBuilder('et')
                    ->orderBy('et.name', 'ASC');
            },
            'property' => 'name'
        ));