ZF2:zend导航中子路线的活动分支.如何? [英] ZF2: Active branch for child routes in zend navigation. How?

查看:69
本文介绍了ZF2:zend导航中子路线的活动分支.如何?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将其作为Zend Framework 2中的路由配置

I have this as route configuration in Zend Framework 2:

'news' => array(
    'type' => 'Literal',
    'options' => array(
        'route' => '/news',
        'defaults' => array(
            '__NAMESPACE__' => __NAMESPACE__ . '\Controller',
            'controller' => 'News',
            'action' => 'index',
            'page' => 1,
        ),
    ),
    'may_terminate' => true,
    'child_routes' => array(
        'index' => array(
            'type' => 'Segment',
            'options' => array(
                'route' => '[/:page]',
                'constraints' => array(
                    'page' => '\d+',
                ),
                'defaults' => array(
                    '__NAMESPACE__' => __NAMESPACE__ . '\Controller',
                    'controller' => 'News',
                    'action' => 'index',
                    'page' => 1,
                ),
            ),
        ),
    ),
),

我还有一个导航,其中一个元素指向路线名称news.

I also have a navigation where an element points to route name news.

当我在/news页面上时,一切都很好,并且新闻导航元素处于活动状态.但是当我在与路线news/index匹配的/news/2上时,导航元素未激活.

When I am on the /news page everything is fine and the news navigation element is active. But when I am on /news/2 which matches route news/index the navigation element isn't active.

我如何告诉它对于绑定到该路由的每个子路由都处于活动状态?

How can I tell it to be active for every child route of the route it is bound to?

推荐答案

您是否已在导航设置中设置了控制器和操作?如果您设置了这些内容,则无论设置哪个页面,它都应该与新闻路线匹配,因为操作/控制器匹配:

Have you set controller and action inside your naviation settings? If you set those it should match the news route no matter which page is set because the action/controller match:

'pages' => array(
     array(
        'label'        => 'News',
        'route'        => 'news',
        'controller'   => 'news',
        'action'      => 'index',
    ),
)

这篇关于ZF2:zend导航中子路线的活动分支.如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆