Я создаю веб-сайт, и мое навигационное меню успешно работает с использованием древовидной структуры, хранящейся в базе данных.
A
Код: Выделить всё
MenuКод: Выделить всё
activeКод: Выделить всё
MenuI've read tons of questions on SO, and also looked at the different bundles available, but I'm still stuck on how to do this.
How would I go about finding out menu item to set as active?
EDIT:
- Menu class: https://gist.github.com/robcaw/c7642695 ... tfile1-php
- Menu controller: https://gist.github.com/robcaw/af18e7c0 ... tfile1-php
Ok, I've almost done it. I've managed to compare the current path, using
Код: Выделить всё
$this->container->get('request')->getPathInfo();Код: Выделить всё
MenuКод: Выделить всё
urlTo do this I needed to flatten the menu tree structure into an array. As I'm using the DoctrineExtensions' Tree extension, I used its repository's
Код: Выделить всё
getChildren($node)In the breadcrumb controller, I can pass the
Код: Выделить всё
$current_itemКод: Выделить всё
getPath()However, there is still a problem, as some pages on the website don't have a menu entry. So for example if I visit
Код: Выделить всё
site.com/news/tags/stuffSo far:
- MenuController: https://gist.github.com/robcaw/61383e26 ... tfile1-php
- BreadcrumbController: https://gist.github.com/robcaw/62341672 ... tfile1-txt
Источник: https://stackoverflow.com/questions/159 ... n-symfony2
Мобильная версия