我在我的KnpMenuBundle应用程序中使用了Symfony2。
我试图使用setAttributes of FactoryInterface of KnpMenuBundle设置菜单KnpMenuBundle属性,如下所示:
$menu = $factory->createItem('root');
$menu->setAttribute('class' , 'sf-menu');但这不管用!带有或不带setAttribute行的结果标记是:
<ul>
<li class="first">
...
</ul>虽然我希望有<ul class='sf-menu'>
有什么问题吗?
发布于 2015-01-15 10:08:11
如果您想给li元素一个类,就必须这样设置它:
$menu->addChild('Label', [
...
'attributes' => ['class' => 'sf-menu'],
]);如果您想给您的ul元素提供一个类:
$menu = $this->factory->createItem('root');
$menu->setChildrenAttribute('class', 'sf-menu');https://stackoverflow.com/questions/27960860
复制相似问题