KnpLabs / KnpMenu

Menu Library for PHP

Home Page:https://knplabs.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Create more than 2-th level

opened this issue · comments

Can I create more than 2-th level of menu (for example admin->settings->users)? Thanks for answer.

Did you try this:

$menu = $app['knp_menu.factory']->createItem('root');
$menu->addChild('admin', array('uri' => '/admin'));
$menu['admin']->addChild('settings', array('uri' => '/admin/settings'));
$menu['admin']['settings']->addChild('users',array('uri'=>'/admin/settings/users'));
return $menu;

what @Kwbmm said is working. Note that ->addChild() also returns the Item object for the new child (the one you would also access with $menu['admin'])