【发布时间】:2012-01-16 01:42:14
【问题描述】:
我在存储库类中使用以下方法在我的数据库中查找某些标签:
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();
}
这很好用。但是:如何添加 2 个附加变量(其中:已审核 = 1,启用 = 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');
// ...
}
也不行……
有什么提示吗?
【问题讨论】: