yii - Yii2: How to use orWhere in andWhere -


i want create query yii2 search model

select * t1 (title = 'keyword' or content = 'keyword') ,                         (category_id = 10 or term_id = 10 ) 

but don't know how use orfilterwhere , andfilterwhere.

my code in search model:

public function search($params) {    $query = app::find();     //...     if ($this->keyword) {          $query->orfilterwhere(['like', 'keyword', $this->keyword])               ->orfilterwhere(['like', 'content', $this->keyword])    }    if ($this->cat) {         $query->orfilterwhere(['category_id'=> $this->cat])               ->orfilterwhere(['term_id'=> $this->cat])    }     //... } 

but creates query:

select * t1 title = 'keyword' or content = 'keyword' or                         category_id = 10 or term_id = 10 

first required sql staement should smth this:

select *  t1  ((title '%keyword%') or (content '%keyword%'))  , ((category_id = 10) or (term_id = 10)) 

so query builder should smth this:

public function search($params) {    $query = app::find();     ...    if ($this->keyword) {          $query->andfilterwhere(['or',             ['like','title',$this->keyword],             ['like','content',$this->keyword]]);    }    if ($this->cat) {         $query->andfilterwhere(['or',             ['category_id'=> $this->cat],             ['term_id'=> $this->cat]]);    }... 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -