ZF2导航:使用非默认参数激活路线?

时间:2013-10-06 01:39:47

标签: php navigation routes zend-framework2

这似乎是一个类似的问题但对我不起作用。我觉得答案必须在那里 - 这不是一个不常见的问题 - 但我没有使用正确的搜索条件。

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>

我的导航显示正确,并且已为家庭和zfcuser路线激活了正确的部分。这是我遇到问题的平台路线。如果我转到/platform,菜单将被激活。但是,当我浏览模块中的任何其他页面时(例如/platform/pendulum/na/af455e),没有活动菜单,也没有面包屑。问题似乎是这些其他页面上的控制器/操作与路由指定的默认值不同。

如何才能获得任何成功的路线匹配以激活菜单?

1 个答案:

答案 0 :(得分:-3)

把这样的东西放在

  'invokables' => array(
        'Application\Controller\Platform'       => 'Application\Controller\PlatformController')

并从上面替换默认

 'defaults' => array(
                'controller' => 'Application\Controller\Platform',
                'action' => 'index',
            ),

应用程序是我案例中的模块名称

相关问题