I have 2 DateTime classes in Symfony2 project. I have entity Stat, in which have $date property.
/**
* @ORM\\Column(type=\"da
I had a similar situation. I couldn't use ->setParameter because of how my code was built, so i put this $andX variable to "catch" all the conditions founded in the foreach loop (in this case i just wrote the one with the dates because other are not relevant right now).
$this->qb = $this->em->createQueryBuilder();
$andX = $this->qb->expr()->andX();
$this->qb->select('u')
->from('models\User','u');
foreach($data as $key=>&$value){
if($key == 'date'){
$from = $this->qb->expr()->gte('u.date_from',$this->qb->expr()->literal($value['datefrom']));
$to = $this->qb->expr()->lte('u.date_to',$this->qb->expr()->literal($value['dateto']));
$condition = $from. ' AND ' .$to;
$andX->add($condition);
}
//other if
}
Notice that the parameter for this function is a multidimensional array. Hope this is helpful.