yii2 where or and like
<?php
// where status='Open' and category='1' and subCategory='1' and (category like '%test%' or subCategory like '%test%' or title like '%test%' or introduction like '%test%')
//@link http://stackoverflow.com/a/31558035/5840474 get and or
//@link http://stackoverflow.com/a/28593956/5840474 get like
$where = array(
array(
'and',
"status='Open'"
)
);
if(!empty($category)){
$where[0][] = "category='$category'";
}
if(!empty($subCategory)){
$where[0][] = "subCategory='$subCategory'";
}
if(!empty($word)){
$where[] = array(
'or',
array('like','category',$word),
array('like','subCategory',$word),
array('like','title',$word),
array('like','introduction',$word),
);
}