I'm trying to populate a choice dropdown in Symfony using the array value of a query performed before the ->add of the form builder. I can't for the life of me get the actual label or value despite the fact that the dump($categories) shows the proper values. The dropdown is populated with just 0,1,2. The Category contains a ->getName and a ->getId but I can't reference these.
$categories = $em->getRepository('AppBundle:Category')
->createQueryBuilder('t')
->where('t.userCreate = :user_id')
->andWhere('t.type = :catType')
->setParameter('user_id',$userID)
->setParameter('catType',$type)
->getQuery()
->getResult();
$builder
->add('taskCategory', 'choice', array(
'choices' => $categories,
'placeholder' => 'Choose a category',
'choices_as_values' => true,
))
entityform type?entityis part of the DoctrineBridge bundle and adds extra functionality for thechoicetype and lots of magic that cannot be explained in brief comment. Btw, instead of passing your categories through$options, since you're usingentitytype, you can include the extra optionquery_builderand pass the callback along with your query - symfony.com/doc/current/reference/forms/types/…