我在一个仓库类中使用以下方法来在我的数据库中查找特定的标签:
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();
}
这个代码非常好用。但是我该如何添加两个额外的变量(其中:reviewed = 1,enabled = 1)?我尝试使用andwhere()但是没弄清楚。
我也发现类似下面的东西:
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');
// ...
}
这也不起作用......
有什么提示吗?