3

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.

j0k
  • 22,600
  • 28
  • 79
  • 90
luxury
  • 159
  • 6
  • 15

1 Answers1

12
$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/

Peyman Mohamadpour
  • 17,954
  • 24
  • 89
  • 100
Dave Mascia
  • 1,364
  • 10
  • 14
  • thanks, thats the answer what I want (included link), and sry for my reputation to vote you up :( – luxury Jul 09 '12 at 02:41
  • I suggest using getter method for child retrieval: $menu->getChild('User'); This way you will get autocomplete (@return ItemInterface) in IDE and you won't break encapsulation OOP concept. – AphonopelmaChalcodes Dec 09 '15 at 18:31