I use some $query->andFilterWhere(...)
to create my query.
and can see the final query by echo $query->createCommand()->rawSql;
when I copy the final query and past it on phpmyadmin, 2 record fetched but no result found in ActiveDataProvider.
Where is the point that I miss that?!
============================================
This is my code:
$query = Camera::find();
$post = Yii::$app->request->post();
$post2 = array_filter((array)$post);
if( count($post2) >0 ){
foreach($post2 as $k=>$v){
$query->andFilterWhere([ 'Like' , $k , $v ]);
}
}
if($post['State'] > 0){
$branches = Branch::find()->joinWith('city')->where('state_id='.((int)$post['State']))->all();
foreach( $branches as &$v){
$v = $v->brch_id;
}
$query->andFilterWhere([ 'IN' , 'brch_id' , $branches ]);
}
echo $query->createCommand()->rawSql;
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
The problem was this loop:
foreach( $branches as &$v){
$v = $v->brch_id;
}
I just replace it by:
$a = [];
foreach( $branches as $v){
$a[] = (int)$v->brch_id;
}
and DONE, Solved!!!!! :|