Answer the question
In order to leave comments, you need to log in
How to display subcategories in breadcrumbs in yii2?
Hello, dear yiigrammers)
Please tell me how to implement breadcrumbs for nested categories.
Those. there is a table:
id | parent_id | alias | title Categories
in it:
Category №1->Subcategory of category №1 -> Subcategory of subcategory of category №1
(/category_1) -> (/category_1/subcategory) -> (category_1/subcategory/sub_subcategory)
I get data about the current category in the following way:
public function actionView($alias)
{
$alias = end(explode('/', $alias));
$catalog_row = Catalog::find()->where(['alias' => $alias])->one();
}
Answer the question
In order to leave comments, you need to log in
The implementation of a tree structure is one of the most hemorrhoidal and often encountered tasks in the web.
https://gist.github.com/codedokode/10539720
Naturally, querying the database in a loop is the bottom ... One of the most elegant methods of course is Nested Tree, which allows almost everything to be implemented with one SQL. And here is a good example, you can copy requests (just substitute your data).
Well, for yii2, Google issued https://habrahabr.ru/post/266155/
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question