Using CRUD with generated GridView on the index page.
At the moment in the GridView displays all the elements from the table in the database.
I wanted that all data would not be displayed, but only those for which, for example, the field some_id in the table is 12 .
I tried this:
In place $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
Posted
$query = SomeModel::find()->where(['some_id' => 12]); $dataProvider = new ActiveDataProvider([ 'query' => $query, 'pagination' => [ 'pageSize' => 20, ], ]); It seems everything turned out, but now searchModel does not work.
Or you can add a condition to the string
$dataProvider = $searchModel->search(Yii::$app->request->queryParams); UPDATE:
In fact, in the controller, actionIndex accepts the parameter some_id , and then displays the data for which the condition is met.
public function actionIndex($some_id){ $searchModel = new SomeModelSearch(); // Я сам закомментировал //$dataProvider = $searchModel->search(Yii::$app->request->queryParams); // И добал это $query = SomeModel::find()->where(['some_id' => $some_id]); $dataProvider = new ActiveDataProvider([ 'query' => $query, 'pagination' => [ 'pageSize' => 20, ], ]); return $this->render('index', [ 'searchModel' => $searchModel, 'dataProvider' => $dataProvider, ]); }
searchModeldoes not work for you for another reason, I just checked it, this option works fine, so I wrote @UrmuzTagizade, I need more code - MasterAlex