I
I
Igor Gula2015-11-10 01:00:24
Yii
Igor Gula, 2015-11-10 01:00:24

How to make categories in Yii2?

I want to implement categories on a Yii2 site.
Here is the news table.
55783cee765546c9a0fc3e99631f66a5.jpg
Here is the category table.
b2d1948b615748708948b152da38a72d.jpg
Linked news and category tables with:
public function getCategory(){
return $this->hasOne(Category::className(),['id'=>'category_id']);
}
It works.
But how can I now make it possible to go to the news at the link: site.com/sport/futbol/dinamo-kiyev-shakhter-donetsk-anons ? (futbol - 2nd level category)
or site.com/sport/ukrainskaya-legkoatletka-blestyashche-vyigrala-etap-kubka-mira (no subcategory) ?
And if you follow the link site.com/sport/futbol/ or site.com/sport/, then there will be a list of news in this category.
Thanks in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
Talgat Baltasov, 2015-11-10
@talgatbaltasov

rename the level category table to parent and store the ID of the parent category there, if this is the parent category, then set it to 0

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question