V
V
Vladislav Sofienko2017-09-01 16:55:54
Yii
Vladislav Sofienko, 2017-09-01 16:55:54

How to add to dataProvider searchModel?

There is this code in index

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

return $this->render('view_all_questions', [
            'searchModel' => $searchModel,
            'dataProvider' => $dataProvider,
]);

But how to shove $searchModel into such a dataProvider?
$dataProvider = new ActiveDataProvider([
            'query' => Question::find()->where('test_id=:test_id', array(':test_id'=>$test_id)),
]);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Timofeev, 2017-09-01
@sofvlad

Note that stuffing the searchModel into the dataProvider is your idea. In fact, right here:
the result of executing the search method from the QuestionSearch object gets into the variable named dataProvider. And not stuffing the searchModel into the dataProvider. And if you look at what is in it (in the search method), then you will find just this or something like that:

$dataProvider = new ActiveDataProvider([
            'query' => 'someQuery'
]);
return $dataProvider;

I think I gave you an idea and you figured it out. If not, specify the question, because you obviously do not need to add dataProvider to the searchModel. Describe a real problem. Let's help.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question