Doctrine2 eq special char expressions to match all

I'm trying to run filters with the doctrine query builder, I use expr eq, but if I don't have a filter value, I would like to use a special character for expr eq, which returns all the rows.

my code is:

$q = $qb->select(array('p')) ->from(payment::class, 'p') ->innerJoin(customer::class, 'z', 'WITH', 'p.customer= z.id') ->where( $qb->expr()->eq('z.id', '?2') ) ->setMaxResults($limit) ->setFirstResult($offset) ->orderBy('p.'.$sortField, $sortType) 

there I want somting like (-> setParameter (2, "*"))

  ->setParameter(2, $filtry['customer']) ->getQuery(); return $q->getResult(); 

Is it possible? I do not want to write different query constructors for each filter.

sorry for my English

thanks

+5
source share
1 answer

This is a query builder, so you can add parameters conditionally, for example:

 $qb->select(array('p')) ->from(payment::class, 'p') ->innerJoin(customer::class, 'z', 'WITH', 'p.customer= z.id') ->setMaxResults($limit) ->setFirstResult($offset) ->orderBy('p.'.$sortField, $sortType) if ($filtry['customer']) { $qb->andWhere( $qb->expr()->eq('z.id', $filtry['customer']) ) }; $q = $qb->getQuery() 

Hope for this help

+3
source

All Articles