学说或者里面和哪里

时间:2015-10-02 19:54:53

标签: php search doctrine-orm doctrine where

如何使用doctrine指定搜索多列?

        $criteria = new Criteria();
        $criteria->where($criteria->expr()->eq('id', $id))
            ->andWhere($criteria->expr()->eq('active', true));

        $search = "Abc";
        if (!empty($search)) {
            $criteria->andWhere(
                $criteria->expr()->contains('column1', $search) || 
                $criteria->expr()->contains('column2', $search)
            );
        }

1 个答案:

答案 0 :(得分:1)

使用orX()

        $criteria->andWhere(
            $criteria->expr()->orX(
                $criteria->expr()->contains('column1', $search),
                $criteria->expr()->contains('column2', $search)
            )
        );