Active Query Function from URL Param

I have an active query class for a specific model with the following function:


public function active()

    {

        return $this->andWhere(['statusId' => [10,20,30,40,50,55]]);

    }

How can I access this filter from a URL string? (ie. route/action?PoSearch[active] or something like this?)

Here is my controller:


public function actionIndex()

    {

        $searchModel = new PoSearch();

        $dataProvider = $searchModel->search(Yii::$app->request->queryParams);


        return $this->render('index', [

            'searchModel' => $searchModel,

            'dataProvider' => $dataProvider,

        ]);

    }

I am pretty new to all this stuff and my code is pretty basic from Gii.




// in PoSearch::search()

$query->andFilterWhere([

    'statusId' => $this->statusId,

]);



Where do I put that code?

I would manually add a property named ‘active’ to PoSearch model.

Then you can add a checkbox for it to the _search form of the index view.




<?= $form->field($model, 'active')->checkBox() ?>



This can create an url like ‘route/action?PoSearch[active]=1’.

And you can handle ‘active’ accordingly in PoSearch::search() method:




if ($this->active) {

    $query = $query->active();

}



[EDIT]

@umneeq and @jacmoe,

@sdpilot doesn’t want to handle individual ‘statusId’, but ‘active’ status as a whole.

[/EDIT]

Oh, gotcha!

@softark,

This worked perfectly. Thanks for your help!