Symfony 4:FormType中的查询生成器

时间:2019-03-21 16:42:22

标签: forms symfony4

我想在我的字段中选择其 etat = 1 的所有对象 为此,我在存储库类中定义了一种方法,其代码如下:

     /**
     * @return MarcheDAO[] Returns an array of MarcheDAO objects
     */
     public function findMarcheEnCours($etat)
     {
         return $this->createQueryBuilder('d')
             ->select('d.nomMarche as marche')
             ->andWhere('d.etat = :etat')
             ->setParameter('etat', $etat)
             ->getQuery()
             ->getResult();
     }

在我的FormType中

 public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('marche', EntityType::class, [
                'class' => MarcheDAO::class,
                'query_builder' => function(MarcheDAORepository $repo) {
                    return $repo->findMarcheEnCours(1);
                },
                'choice_label' => 'MarcheDAO.nomMarche'

            ])

那是我的错误,

Argument 1 passed to App\Form\SoumissionType::App\Form\{closure}() must be an instance of App\Form\MarcheDAORepository, instance of App\Repository\MarcheDAORepository given, called in C:\wamp\www\AppelsOffres\vendor\symfony\doctrine-bridge\Form\Type\EntityType.php on line 32

            'query_builder' => function(MarcheDAORepository $repo) {..

请帮我!!

0 个答案:

没有答案