Answer the question
In order to leave comments, you need to log in
How to make categories in Yii2?
I want to implement categories on a Yii2 site.
Here is the news table.
Here is the category table.
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
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 questionAsk a Question
731 491 924 answers to any question