Search code examples
symfonymenuknpmenu

How to create a menu of tree items by KnpMenu in symfony2


I'd like to create a ul like following:

<ul>
    <li>
       <a><a>
       <ul>......</ul>
    </li>
</ul>

The sub ul would be another sub item, I have no idea how to create it, any one could help me thanks.


Solution

  • $menu = $factory->createItem('root');
    
    $menu
        ->setChildrenAttribute('class', 'nav pull-right');
    
    $menu
        ->addChild('User')
        ->setAttribute('dropdown', true);
    
    $menu['User']
        ->addChild('Profile', array(
            'uri' => '#'
        ))
        ->setAttribute('divider_append', true);
    
    $menu['User']
        ->addChild('Logout', array(
            'uri' => '#'
        ));
    

    More information: http://linkofy.wordpress.com/2012/04/02/using-knpmenubundle-and-twitter-bootstrap/