A
A
Alexander Stepanov2018-02-04 09:56:03
Yii
Alexander Stepanov, 2018-02-04 09:56:03

How to display items from root and child categories in listView Yii2?

There are two tables category and item.
A category can have a parent_id i.e. There are parent and child categories.
When a parent is selected, returns only the item with that parent's category_id.
How to add item output from child categories as well?
I tried something all night, but to no avail...
The maximum that happened was to get an array of child categories.

public function getChilds($id)
    {
        $query = Category::find()->where(['parent_id' => $id])->all();
        return $query;
    }

And all this still needs to be displayed through the listView ...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Stepanov, 2018-02-05
@Exebeche

It seems you need to somehow pass the array to this action in ProductSearch

$query->andFilterWhere([
            'id' => $this->id,
            'category_id' => $this->category_id,
        ]);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question