Yii2不止一个OR条件

时间:2016-08-22 13:58:17

标签: activerecord yii2

我如何使用多个OR

$data = Info::find()
    ->andFilterWhere(['OR',
        [ 'LIKE', 'username LIKE "%' . $text . '%" '],
        [ 'LIKE', 'name LIKE "%' . $text . '%" '],
        [ 'LIKE', 'data LIKE "%' . $text . '%" '],
        [ 'LIKE', 'skype LIKE "%' . $text . '%" '],
        [ 'LIKE', 'position LIKE "%' . $text . '%" '],
        [ 'LIKE', 'duties LIKE "%' . $text . '%" '],
        [ 'LIKE', 'position_en LIKE "%' . $text . '%" '],
        [ 'LIKE', 'display_name_en LIKE "%' . $text . '%" '],
    ])
    ->asArray()
    ->all();

1 个答案:

答案 0 :(得分:2)

使用它的正确方法是:

while

#include <iostream> int main() { int* foo = nullptr; int& refint = *foo; if(&refint == nullptr) std::cout << "Null" << std::endl; else std::cout << "Value " << refint << std::endl; } $data = Info::find() ->andFilterWhere(['or', ['like', 'username', $text], ['like', 'name', $text], ['like', 'data', $text], ['like', 'skype', $text], ['like', 'position', $text], ['like', 'duties', $text], ['like', 'position_en', $text], ['like', 'display_name_en', $text], ]) ->asArray() ->all(); 之间的区别在于第一个忽略空查询操作数。