Hi guys, I have a challenge with the current ‘if($model->load(Yii::$app->request->post()) ) ‘ statement. The limit of four brands loads properly when a brand is selected from the index page. When page 2 of the available brands is selected the index is rendered rather than page 2. If someone could direct me toward a 1)better conditional option or 2)a better way of selecting brands from a menu, I would greatly appreciate it. Thanks for your time.
Controller
public function actionIndex()
{
$model = new Products();
if($model->load(Yii::$app->request->post()) )
{
$id = $model->brand_id;
$query = Products::find()
->where(['brand_id' => $id])
->joinWith(['power', 'categories']);
$pagination = new Pagination([
'defaultPageSize' =>4,
'totalCount' => $query->count(),
]);
$products = $query
->orderBy('product_name')
->offset($pagination->offset)
->limit($pagination->limit)
->all();
return $this->render ('viewProducts', [
'products' => $products,
'pagination' => $pagination,
]);
} else {
return $this->render('index', [
'model' => $model,
]);
}
}