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.
$qb->select('u')
->from('UserBundle:User', 'u')
->orderBy('u.firstName', 'ASC');
if($identifier) {
$qb->where('u.location = :identifier')
->setParameter('identifier', 2);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With