Symfony 2 - how to pass data to formBuilder?

前端 未结 6 631
独厮守ぢ
独厮守ぢ 2020-11-30 03:50

I\'m using entity choice list in my form. I want to use only specific entities (in example: only groups that user belongs to) So, in controller, I\'m getting these groups, a

6条回答
  •  感情败类
    2020-11-30 04:22

    Bacteries' solution is a real good one. Just a note to save headache to other guy like me :)

    In this part may I point out the use ($company) part. It was hidden by the frame and of course nothing works properly without it.

    $builder->add('ad', 'entity', array(
       'class' => 
          '\Your\Bundle\Entity\Ad',
       'query_builder' => 
          function(\Your\Bundle\Repository\AdRepository $er) use ($company) {
                return $er->getActiveAdsQueryBuilder($company);
          },
        )
    );
    

提交回复
热议问题