相关文章推荐
怕老婆的柠檬  ·  Perl ...·  1 年前    · 
怕考试的苹果  ·  在React ...·  2 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

When I do this $builder->add('teams'); it lists all my teams on my form AND an empty choice, so it's possible to have no team or to remove the team (and that behavior is great for what I have to do).

But when I use a query_builder

$builder->add('teams', EntityType::class, array(
                    'class' => Team::class,
                    'query_builder' => function (EntityRepository $er) {
                        return $er->getTeamsNotRestrictedByAdmin();
                    'choice_label' => '_name'

it returns the entities I want but I don't have that null choice anymore. How could I get it back properly ?

$builder->add('teams', EntityType::class, array(
                    'class' => Team::class,
                    'query_builder' => function (EntityRepository $er) {
                        return $er->getTeamsNotRestrictedByAdmin();
                    'choice_label' => '_name',
                    'required' => false,
                    'empty_data' => ''
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.