Создание хлебных крошек в Symfony2Php

Кемеровские программисты php общаются здесь
Ответить
Anonymous
 Создание хлебных крошек в Symfony2

Сообщение Anonymous »


Я создаю веб-сайт, и мое навигационное меню успешно работает с использованием древовидной структуры, хранящейся в базе данных.

A object as a property, but I don't know how to go about setting it to active! If I can do that, then I can get the path of the currently active and render the breadcrumbs using WhiteOctober's BreadcrumbsBundle or something similar.

I'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:
EDIT 2:

Ok, I've almost done it. I've managed to compare the current path, using

Код: Выделить всё

$this->container->get('request')->getPathInfo();
to a 's set .

To 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)
to do this. So now iterating over the array is easy and can compare the url and path.

In the breadcrumb controller, I can pass the

Код: Выделить всё

$current_item
from the menu controller, and again use the Tree repository and its

Код: Выделить всё

getPath()
method which recursively gets parents of the given node.

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/stuff
, there is no menu entry for it and so breaks the site.

So far:


Источник: https://stackoverflow.com/questions/159 ... n-symfony2
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Php»