I am using following method in a repository class to look for certain tags in my database:
public function getItemsByTag($tag, $limit = null)
{
$tag = '%'.$tag.'%';
$qb = $this->createQueryBuilder('c');
$qb->select('c')
->where($qb->expr()->like('c.tags', '?1'))
->setParameter(1, $tag)
->addOrderBy('c.clicks', 'DESC');
if (false === is_null($limit))
$qb->setMaxResults($limit);
return $qb->getQuery()->getResult();
}
This works just nice.. But: How can I add 2 additional variables (where: reviewed = 1, enabled = 1)? I tried andwhere() but I couldn't figure it out.
I also found out that something like this:
public function getItems($limit = null)
{
$qb = $this->createQueryBuilder('b')
->select('b')
->add('where', 'b.reviewed = 1')
->add('where', 'b.enabled = 1')
->addOrderBy('b.name', 'ASC');
// ...
}
won't work either...
Any hints?
I would write it like this:
You could also unite those
where
conditions:From the manual, the suggested way is like below: