default on search

Hello,

In my student model, I have a flag called "active".

This is obviously to show the student is an active student.

After I generated the CRUD, I wanted to change the initial filter on the index view so it first of all only shows students who have active set to true.

Then if the user wants to show all the students, they can by clearing the initial filter.

So I guess the question is, how do I set a default value on the search filter when I first load the view?

Thanks,

Mark

See below screenshot for what I mean

6405

default would like.jpg

In your controller :




public function actionIndex()

{

  $searchModel = new SearchStudent();

  $searchModel->active = 1;//Here

  $dataProvider = $searchModel->search(Yii::$app->request->queryParams);//Will be overwritten if in params

  ...

}



AH HA!!!

I knew there would be a simple answer!

Works great!

Thank you again Timmy78!