【问题标题】:ZF2 Navigation: Activate route with parameters other than default?ZF2 导航:使用非默认参数激活路线?
【发布时间】: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)时,没有活动菜单和面包屑。问题似乎是这些其他页面上的控制器/动作与路由指定的默认值不一样。

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

【问题讨论】:

标签: php navigation routes zend-framework2


【解决方案1】:

把这样的东西放进去

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

并像这样替换上面的默认值

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

Application 在我的例子中是模块名称

【讨论】:

  • 这个答案与问题无关。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-05-12
  • 2019-06-21
  • 2020-01-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-08-01
相关资源
最近更新 更多