문제

I have an entity for publications with many different fields as booktitle, conference etc. I want to build a search form and one of the feature requests is to combine two search parameters in a single choice field. So far I have something like this in the form builder:

$builder->add('booktitle', 'entity', array(
              'required' => false, 
              'label' => 'Conference/Booktitle',
              'property' => 'booktitle',
              'class' => 'indPubBundle:Publication', 
              'query_builder' => function(EntityRepository $er) {
                     return $er->createQueryBuilder('p')
                               ->groupBy('p.booktitle')
                               ->orderBy('p.booktitle', 'ASC');
                      }
              ));

Basically I am displaying all booktitles as a choice field. What I want now is to have the conferences as well in the same choice field. Is there a way to achieve that?

도움이 되었습니까?

해결책

The Entity field type is a child of the Choice field type. So you can provide Data via the "choices" parameter. Combine that with a (e.g. repository) method that returns an array with the data you need might be a solution that works for you.

$builder->add('booktitle', 'entity', array(
            'required' => false,
            'label' => 'Conference/Booktitle',
            'class' => 'indPubBundle:Publication',
            'choices' => $this->getDoctrine()->getRepository('indPubBundle:Publication')->getData(),
        ));
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top