1

This is in controller

$candidats = $repository->findList(
$data["recherche_candidat"]["diplomes"],
$data["recherche_candidat"]["categories"]);

And this in the repository

public function findList($diplomes,$categories,)
{
    $qb=$this->createQueryBuilder('c');

    if($categories!=null){
        $qb->andWhere('c.categorie IN (:value)')
            ->setParameter(':value', $categories);
    }

    if($diplomes!=null) {
        $qb->andWhere('c.diplome IN (:value)')
            ->setParameter(':value', $diplomes);
    }

    return $qb
        ->getQuery()
        ->getResult();
}

problem is when diplomes and categories not null I see an error :

Too many parameters: the query defines 1 parameters and you bound 2

With one null its work; for example diplomes==null and categories!=null it work without error

Community
  • 1
  • 1
Khalil
  • 288
  • 3
  • 16

1 Answers1

6

You are giving the same name for both your parameters therefore Doctrine can't make the difference and only recognize 1 parameter. Do something like this:

public function findList($diplomes,$categories,) {
    $qb=$this->createQueryBuilder('c');

    if($categories!=null){
        $qb->andWhere('c.categorie IN (:categories)')
            ->setParameter(':categories', $categories);
    }

    if($diplomes!=null) {
        $qb->andWhere('c.diplome IN (:diplomes)')
            ->setParameter(':diplomes', $diplomes);
    }

    return $qb
        ->getQuery()
        ->getResult(); 
}
Gregoire Ducharme
  • 1,095
  • 12
  • 24
  • I think you should not include ':' in the name when setting the parameter. Instead of setParameter(':value', $categories), try setParameter('value', $categories); – Declan Whelan May 22 '20 at 21:02