在我当前的Web应用程序中,我正在使用KnpMenuBuilder和Bootstrap来制作菜单。我想在列表项元素中添加一个无序列表,以便它显示为下拉菜单,就像Bootstrap文档中给出的example(s)一样。为此,我还应该为此dropdown-menu
标记添加<ul></ul>
类。看起来应该是这样的:
<ul>
<li>
...
</li>
<li><!-- or this should be <li class="dropdown"> not entirely sure
if this happens with javascript or something yet -->
<a href="#" class="dropdown-toggle">
Dropdown
</a>
<ul class="dropdown-menu">
<li>Dropdown menu item 1</li>
<li>Dropdown menu item 2</li>
</ul>
</li>
</ul>
我知道你可以在MenuBuilder类中添加这样的元素:
public function mainMenu(FactoryInterface $factory, array $options)
{
$menu = $factory->createItem('root', array(
'childrenAttributes' => array(
'class' => 'nav navbar-nav',
),
));
$menu->addChild('Home', array('route' => 'home'));
$menu->addChild('Movies', array('route' => 'movies'))
->setAttribute('class', 'dropdown');
$menu['Movies']->addChild('Add a movie', array('route' => 'movie_create_form'));
//This renders <li><a href="#">movies</a><ul><li><a href="#">Add a movie</a></li></ul></li>
//I want to add the drop-down class to the <ul></ul> tag
return $menu;
}
我目前的结果:
<!-- Ofcourse <ul> tag should be around this aswell, but my question is not about the beauty of this code -->
<li>...</li>
<li dropdown="dropdown" class="active last">
<a href="#">
Dropdown
</a>
<ul class="menu_level_1">
<li class="first last">
<a href="#">
Dropdown menu item 1
</a>
</li>
</ul>
</li>
或者:http://pastebin.com/XHyYeWer
(原文:http://pastebin.com/gnK2G0uz)
我应该如何更改我的(构建器类)代码?
提前致谢。