简体   繁体   中英

symfony2 form entity add values

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 !

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

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');
       },
     ));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM