V
V
Victor Umansky2017-08-24 21:35:45
Yii
Victor Umansky, 2017-08-24 21:35:45

Can't display certain categories?

I can't figure out how to display certain categories. When I go to which category, then all the products from different categories are displayed, as if everything is in a bunch. I can't figure out where to take the $id to pass that selected category, and there, for example, it was possible to filter the product by the category that the user selected.
Previously, site.loc/category/index?id=18
CategoryController was displayed like this before, this was before without model search

public function actionIndex($id)
{
    $query = ProductPit::getProductByStatus($id);
    $countQuery = clone $query;

    $pagination = new Pagination(
        [
            'defaultPageSize' => 21,
            'totalCount' => $countQuery->count(),
            'forcePageParam' => false,
            'pageSizeParam' => false
        ]
    );

    $models = $countQuery
        ->offset($pagination->offset)
        ->limit($pagination->limit)
        ->all();

    if (empty($models)) {
        throw new HttpException(404, 'Категория не найдена');
    }

    return $this->render('index', [
 'models' => $models, 
 'pagination' => $pagination
]);
}

And now I have model search and CategoryController code like this, and I also use listView
public function actionIndex()
{
    $searchModel = new ProductPitSearch();
    $dataProvider = $searchModel->search(Yii::$app->request->queryParams);

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

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Fedorov, 2017-08-25
@qonand

Actually, as before, you need to pass the id of the selected category to the controller using the address bar, then from the controller pass them to the search model, well, in the search model you need to declare the corresponding property and search for it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question