Can i use query in form builder to get filtered collection in symfony form

前端 未结 5 767
伪装坚强ぢ
伪装坚强ぢ 2021-02-05 16:42

IN the AcmePizza BUndle this is working fine

->add(\'pizza\', \'entity\', array(
                \'class\'         => \'Acme\\PizzaBundle\\Entity\\Pizza\',         


        
5条回答
  •  别那么骄傲
    2021-02-05 17:22

    Yes.

    In your UserTaskType class, add the following method.

    public function getDefaultOptions(array $options)
    {
        return array(
            'data_class' => 'acme\myBundle\Entity\UserTask',
            'query_builder' => function($repo) {
                return $repo->createQueryBuilder('p')->orderBy('p.name', 'ASC');
            }
        );
    }
    

提交回复
热议问题