【发布时间】:2014-07-24 14:41:57
【问题描述】:
您好,我在 Doctrine 的 QueryByilder 中遇到问题。我写了一个有 2 个参数的查询,它们影响 where 语句。如果相关参数为空,我想忽略 where 语句。例如,如果 $play = 3 和 $theater = null 查询必须返回所有带有 play 3 和任何剧院的门票 这是我的代码:
public function getAllSearchedTickets($play,$teater){
return $this->getEntityManager()->createQuery('
select s from mtadminBundle:ReserveLocation s
join s.reserve a
join a.sance b
where a.acceptCode != 0
and b.play = :play
and b.teater = :teater')
->setParameters(array('play'=>$play,'teater'=>$teater))->getResult();
}
谢谢。
【问题讨论】: