I used the CRUD generator in Yii2 and it generated the following code for my actionIndex
controller...
public function actionIndex()
{
$searchModel = new LeadSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
I am trying to do two things to this default code:
1) Set the page size so that the gridview displaying it only shows 10 rows
2) Modify the $searchModel
such that it only returns records where the status column in the table matches certain multiple values (IN Operator)... or better yet, all records that don't match a given value.
For #1, I see many examples to set the 'pagination' while using ActiveDataProvider
, but none for search()
. This code didn't work for me...
$dataProvider = $searchModel->search(
Yii::$app->request->queryParams, ['pagination' => [ 'pageSize' => 10 ]]
);
For #2, I know we can filter by declaring the new LeadSearch object as...
$searchModel = new LeadSearch([ 'status' => 'open' ]);
...but something like this doesn't work...
$searchModel = new LeadSearch([ 'status' => ['open', 'pending'] ]);