Symfony2 +主义:使用数组的多重条件

trrrrrrm

我有一个实体,我正在尝试在其存储库中创建以下功能

function customGet(array $criteria)
{
     //WHAT I'm trying to do:
     //SELECT *
     //FROM mytable
     //LEFT JOIN anothoer table
     //WHERE criteria1 = value1 AND criteria2 = value2 ...etc

     $q = $this
        ->createQueryBuilder('u')
        ->select('u, g')
        ->leftJoin('u.theOtherTable', 'g');
        //Where here
        ->getQuery();
}

我该如何处理where子句?

Leetbulb
    $q = $this->createQueryBuilder('u')
        ->select('u, g')
        ->leftJoin('u.theOtherTable', 'g');

    foreach ($criteria as $field => $value) {
        $q->andWhere(sprintf('u.%s = :%s', $field, $field))
          ->setParameter($field, $value);
    }

    return $q->getQuery();

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章