根据匹配路线设置当前项目(KnpMenuBundle)

时间:2012-10-05 04:59:20

标签: symfony knpmenubundle

我有这个建设者

namespace Telnet\CSSBundle\Menu;
use Knp\Menu\FactoryInterface;
use Symfony\Component\DependencyInjection\ContainerAware;
class Builder extends ContainerAware
{
    public function mainMenu(FactoryInterface $factory, array $options)
    {
        $menu = $factory->createItem('Main Menu');
        $menu->addChild('Главная', array('route' => 'pages_index'));
        $menu->addChild('Форум', array('uri' => '/forum'));
        $menu->addChild('Демки', array('route' => 'pages_dem'));
        $menu->addChild('SourceBans', array('uri' => '/sourcebans'));
        $menu->addChild('HLStatsX', array('uri' => '/hlstatx'));
        return $menu;
    }
}

如何在设置当前项目的任何操作中获取此菜单?

1 个答案:

答案 0 :(得分:0)

你缺少这部分逻辑:

$menu->setCurrentUri($this->container->get('request')->getRequestUri());