ZF2: active branch for child routes in zend navigation. How?

I have this as a route setup 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 the element points to the name of the route news

.

When I am on the page /news

, everything is fine and the news navigation item is active. But when I am on /news/2

that which matches the route news/index

, the nav is not active.

How can I tell that it is active for every child route of the route it is attached to?

+3


source to share


1 answer


Have you set the controller and action inside your navigation settings? If you set the ones that should match the news route no matter which page is set because the action / controller is the same:



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

      

+2


source







All Articles