Answer the question
In order to leave comments, you need to log in
Why doesn't searchModel.Yii2 work?
Good afternoon, if I write like this:
public function actionIndex()
{
$searchModel = new OrdersSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
$dataProvider = new ActiveDataProvider([
'query' => Orders::find(),
'pagination' => [
'pageSize' => 10,
'forcePageParam' => false,
'pageSizeParam' => false
],
'sort' => [
'defaultOrder' => [
'statys' => SORT_ASC
]
]
]);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
Answer the question
In order to leave comments, you need to log in
I understand that I am overriding $dataProvider
'query' => Orders::find(),
'pagination' => [
'pageSize' => 10,
'forcePageParam' => false,
'pageSizeParam' => false
],
'sort' => [
'defaultOrder' => [
'statys' => SORT_ASC
]
]
public function actionIndex()
{
$searchModel = new OrdersSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
$dataProvider->setSort([
'defaultOrder' => [
'statys' => SORT_ASC
]
]);
$dataProvider->setPagination([
'pageSize' => 10,
'forcePageParam' => false,
'pageSizeParam' => false
]);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
all work with the Data Provider takes place in the search method of the OrdersSearch class, there is no need to override it in the controller.
In what form do you display data in the view? GridView or ListView?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question