I have this query
$qb->select('u')
->from('UserBundle:User', 'u')
->where('u.location = :identifier')
->orderBy('u.firstName', 'ASC')
->setParameter('identifier', 2);
I want that if $identifier is present then it should filter the results otherwise i get all the results like
$qb->select('u')
->from('UserBundle:User', 'u')
if($identifier)
->where('u.location = :identifier')
->orderBy('u.firstName', 'ASC')
if($identifier)
->setParameter('identifier', 2);
Is it possible
It is possible, you just have to restructure your code.