3

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,
                ),
            ),
        ),
    ),
),

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

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?

Daniel M
  • 3,369
  • 20
  • 30
Tony Bogdanov
  • 7,436
  • 10
  • 49
  • 80
  • Come to think of it, it is done correctly by not having such a situation in mind, because zend navigation can't know of the individual structure of the route for each project. A solution that would work would be to add subpages to the navigation for each subpage to the given route there is and fill it with dummy values, then hide it (render the first level only), I believe this would make the parents active since one of their children will match the request. But, that's quite a dirty solution, don't you think? – Tony Bogdanov Jan 25 '13 at 13:08

1 Answers1

2

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',
    ),
)
Andrew
  • 12,617
  • 1
  • 34
  • 48