Zend2导航从数组传递到ZendNavigationNavigation
工作良好,如果子项目打开父项目鼠标悬停。如果他们打开鼠标点击不良行为发生。用户不能直接转到子页面。打开父菜单项的第一页。
<nav>
<ul class="sidebar">
<li>
<a class="item-1" href="parent-page1">Parent page1</a>
<ul>
<li>
<a class="item-1" href="child-page11">Child page11</a>
</li>
<li>
<a class="item-1" href="child-page12">Child page12</a>
</li>
</ul>
</li>
<li>
<a class="item-1" href="parent-page2">Parent page2</a>
<ul>
<li>
<a class="item-1" href="child-page21">Child page21</a>
</li>
<li>
<a class="item-1" href="child-page22">Child page22</a>
</li>
</ul>
</li>
问题可以解决,如果有一个选项,从父项完全删除"href"属性。然而,我在Zend2文档或示例中找不到这样的选项。我认为这是我的错,因为必须有一些可能解析菜单与可单击的父项。该类型菜单用于流行的管理面板,如AdminLTE。
现在我使用的解决方案看起来不太好。在导航数组中,我将'class' => 'not-active'
添加到每个父项。然后在应用程序布局中,JavaScript完成
window.onload = function () {
x = document.getElementsByClassName("not-active");
for(var i=0,j=x.length; i<j; i++){
x[i].removeAttribute("href");
};
}
编辑
终于找到了解决方案。必须在module.config.php
中添加新路由
'empty' => array(
'type' => 'ZendMvcRouterHttpLiteral',
'options' => array('route' => '#'),
),
然后在导航数组
中使用 array(
'label' => 'Parent page1',
'route' => 'empty',
'controller' => 'admins',
'resource' => 'AdminControllerAdmins',
'privilege' => 'index',
'pages' => array(
array(
'label' => 'Child page11',
'route' => 'admin/default',
'controller' => 'admins',
'resource' => 'AdminControllerModules',
'privilege' => 'index',
),
array(
'label' => 'Child page12',
'route' => 'admin/default',
'controller' => 'modules',
'resource' => 'AdminControllerModules',
'privilege' => 'index',
),
),
),
编辑2
不幸的是,当站点位于子路径时,解决方案不起作用。
我从example.com
得到<a href="#">Parent 1</a>
but <a href="subpath/#">Parent 1</a>
from example.com/subpath/
您可以简单地添加# as parent href.
<a href="#">Parent 1</a>
点击浏览器,不要重新加载或去别的地方,你留在那个网站上