Let’s say I have a category Gridview. Each categories have many products. I want to list the products in a new Gridview for each categories.
I can do it, and I can sort the results for “id” and “title” but I don’t know how to search for the products.
If I look at the Index view, with Gridview, I see this: $dataProvider = $searchModel->search($_GET);
But here, I have a new $dataprovider for the products and I don’t know how to set the $searchModel
/* in category controller */
<? php
public function actionViewproducts($id)
{
$searchModel = new \common\models\search\ProductSearch(); /* not sure */
$dataProvider = new ActiveDataProvider([
'query' => \common\models\Product::find()
->where(['category_id' => $id]),
'pagination' => [
'pageSize' => 20,
],
]);
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
'category'=> $this->findModel($id),
]);
}
Thanks!