如何使用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)
);
}
答案 0 :(得分:1)
使用orX()
:
$criteria->andWhere(
$criteria->expr()->orX(
$criteria->expr()->contains('column1', $search),
$criteria->expr()->contains('column2', $search)
)
);