【发布时间】:2013-10-06 01:39:46
【问题描述】:
这似乎是一个类似的问题,但对我不起作用。我觉得答案肯定就在那里——这不是一个不常见的问题——但我没有使用正确的搜索词。
ZF2: Active branch for child routes in zend navigation. How?
这是我定义的路线:
'router' => array(
'routes' => array(
'platform' => array(
'type' => 'segment',
'options' => array(
'route' => '/platform[/:controller/:region/:id[/:action]]',
'constraints' => array(
'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'region' => '[0-9a-z]{2,4}',
'id' => '[0-9a-z-]+',
),
'defaults' => array(
'controller' => 'platform',
'action' => 'index',
),
),
),
),
),
这是我的导航:
'navigation' => array(
'default' => array(
array(
'label' => 'Home',
'route' => 'home',
),
array(
'label' => 'Account',
'route' => 'zfcuser',
'pages' => array(
array(
'label' => 'Dashboard',
'route' => 'zfcuser',
),
array(
'label' => 'Sign In',
'route' => 'zfcuser/login',
),
array(
'label' => 'Sign Out',
'route' => 'zfcuser/logout',
),
array(
'label' => 'Register',
'route' => 'zfcuser/register',
),
),
),
array(
'label' => 'Platform v2 BETA',
'route' => 'platform',
),
),
),
我在布局中的每个页面上都显示一个顶级菜单,如下所示:
<div class="nav-collapse collapse">
<?php echo $this->navigation('navigation')
->menu()
->setMinDepth(0)
->setMaxDepth(0)
->setUlClass('nav')
->render(); ?>
</div>
我的导航显示正确,并且为 home 和 zfcuser 路线激活了正确的部分。这是我遇到问题的平台路线。如果我去/platform,菜单将被激活。但是,当我浏览到模块中的任何其他页面(例如/platform/pendulum/na/af455e)时,没有活动菜单和面包屑。问题似乎是这些其他页面上的控制器/动作与路由指定的默认值不一样。
如何获得任何成功的路线匹配以激活菜单?
【问题讨论】:
-
我遇到了类似的问题,这个解决方案帮助了我:stackoverflow.com/a/18878776/5932318
标签: php navigation routes zend-framework2