$searchModel = new SearchModel();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
if (!empty(Yii::$app->request->queryParams)) {
// $dataProvider->keys = [1, 2, 3]
$IDArray = Model::someFunction($dataProvider->keys);
$dataProvider->query->andWhere(['NOT IN', 'id', $IDArray]); // $IDArray = [1,2]
}
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
$dataProvider->keys = [3];
$dataProvider->keys = [1, 2, 3];
Although checked that query appended correctly with $dataProvder->query
yii\db\ActiveQuery#1
(
[sql] => null
[on] => null
[select] => null
[selectOption] => null
[distinct] => null
[from] => null
[groupBy] => null
[join] => null
[having] => null
[union] => null
[params] => []
[yii\base\Component:_events] => []
[yii\base\Component:_behaviors] => []
[where] => [
0 => 'and'
1 => [
'test_id' => '2'
]
2 => [
0 => 'NOT IN'
1 => 'id'
2 => [
0 => 1
1 => 2
]
]
]
..
..
..
..
For temporary Workaround using
$clone = clone $dataProvider;
$IDArray = Model::someFunction($clone->keys);
| Q | A
| ---------------- | ---
| Yii version | 2.0.9
| PHP version |7.0.13-1+deb.sury.org~precise+1
| Operating system |Ubuntu
After accessing keys they are cached to avoid duplicate queries. to refresh the data in the dataprovider, call $dataProvider->refresh(). http://www.yiiframework.com/doc-2.0/yii-data-basedataprovider.html#refresh%28%29-detail
@cebe Thanks. Should read guide properly. Sorry for lame issue.
Most helpful comment
After accessing keys they are cached to avoid duplicate queries. to refresh the data in the dataprovider, call
$dataProvider->refresh(). http://www.yiiframework.com/doc-2.0/yii-data-basedataprovider.html#refresh%28%29-detail