我们如何在Doctrine的条件下写IN语句

时间:2013-10-07 12:59:26

标签: symfony dql

我有一个类别的数组, 如何在使用Doctrine的类中使用IN语句?

1 个答案:

答案 0 :(得分:-1)

你可以这样使用

public function searchCategory($target){//$target is an aray(1,2,3)

      $query = $this->getEntityManager()
                    ->createQuery("SELECT abc ct.target as target FROM AdminBundle:ClothingType ct WHERE ct.target IN (:target)")
                     ->setParameter('target',$target['target']);// You can change it as ur requirment 
                     try {
                     return $query->getResult();
                } catch (\Doctrine\ORM\NoResultException $e) {
                return null;
                }

}