Reputation: 633
I just need to add other defaults options to an "entity field" in Symfony2. It displays names, and I need an option "Name not in list", but I cant find a way to achieve it. Data transformers cant seem to fix my problem though.
$builder
->add('family', 'entity', array(
'class' => 'InterneFichierBundle:Family',
'property' => 'Name'
))
If the name of the family is not in the list, there should be an option "name not in list".. Thanks a lot !
Upvotes: 0
Views: 933
Reputation: 2769
i'm pretty sure you can just specify an empty value option:
$builder
->add('family', 'entity', array(
'class' => 'InterneFichierBundle:Family',
'property' => 'Name',
'empty_value' => 'Name not in list',
))
see http://symfony.com/doc/current/reference/forms/types/entity.html#empty-value
Upvotes: 1
Reputation: 872
You shouk try with :
for information you can see it here : http://symfony.com/fr/doc/current/reference/forms/types/entity.html
$builder->add('users', 'entity', array(
'class' => 'AcmeHelloBundle:User',
'query_builder' => function(EntityRepository $er) {
return $er->createQueryBuilder('u')
->orderBy('u.username', 'ASC');
},
));
Upvotes: 0