Reputation: 1771
I have a form which has these three fields. So in catalogLevelId, I dont need all the data in the dropdown but only some. How to do this?
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('title')
->add('parent', 'entity', array('class' => 'RetailMappingCatalogBundle:Catalog', 'property' => 'title'))
->add('catalogLevelId', 'entity', array('class' => 'RetailMappingCatalogBundle:CatalogLevel', 'property' => 'name'))
->add('save', 'submit', array('label' => 'Submit'))
;
}
Upvotes: 0
Views: 60
Reputation: 236
The query builder can do this for you, did you already try ?
use Doctrine\ORM\EntityRepository;
->add('catalogLevelId', 'entity',
array (
...,
'query_builder' => function(EntityRepository $er) {
return $er->createQueryBuilder('c')
->orderBy('c.name', 'ASC');
}))
Upvotes: 1