2016-04-23 46 views

回答

0

如果knp_menu_render功能,我们将调用模板的appbundle:菜单:knp_menu.html.twig 然后移动演示菜单文件为src /的appbundle /资源/视图/菜单/ knp_menu.html.twig喜欢这里的文档:http://symfony.com/doc/current/book/templating.html#template-naming-and-locations

通过以下步骤:

在模板中写:

{{ knp_menu_render('AppBundle:Builder:mainMenu', 'template': 'AppBundle:Menu:knp_menu.html.twig'}) }} 

拷贝文件:

/SRC /的appbundle /菜单的10

例Builder.php

<?php 
namespace AppBundle\Menu; 

use Knp\Menu\FactoryInterface; 
use Symfony\Component\DependencyInjection\ContainerAwareInterface; 
use Symfony\Component\DependencyInjection\ContainerAwareTrait; 

class Builder implements ContainerAwareInterface 
{ 
    use ContainerAwareTrait; 

    public function mainMenu(FactoryInterface $factory, array $options) 
    { 
     $menu = $factory->createItem('root'); 

     $menu->addChild('Main', array('route' => 'homepage')); 
     $menu->setChildrenAttribute('class', 'nav navbar-nav'); 

     // create another menu item 
     $menu->addChild('About', array('route' => 'About')); 
     $menu['About']->addChild('Contacts', array('route' => 'About')); 
     $menu['About']->addChild('Contacts1', array('route' => 'About')); 
     $menu['About']->setChildrenAttribute('class', 'dropdown-menu'); 
     // ... add more children 

     return $menu; 
    } 
}