7
votes

Build navigation from config:

'navigation' => array(
    'default' => array(
        'admin' => array(
                'label' => 'Administration',
                'controller' => 'index',
                'action' => 'index',
                'route' => 'admin/default',
              ),
         'album' => array(
                'label' => 'Album',
                'controller' => 'index',
                'action' => 'index',
                'route' => 'album/default',
              ),
  /* ... */

Routing is configured like it is true. Navigation in the menu works. Links menu lead to the desired controller/action of the desired module. But while introducing menu and a transition to one or another menuitem, active marked both points simultaneously and 'Administration' and 'Album'. As I understand it, for the reason that match the names of controllers and actions with them, but there's still the 'route' and it's different... not for nothing that the generated different url for each item... but somehow, despite this, they both are marked as active.

Routing config:

    'router' => array(
    'routes' => array(
        'admin' => array(
            'type'    => 'Literal',
            'options' => array(
                'route'    => '/admin',
                'defaults' => array(
                    '__NAMESPACE__' => 'Admin\Controller',
                    'controller'    => 'Index',
                    'action'        => 'index',
                ),
            ),
            'may_terminate' => true,
            'child_routes' => array(
                'default' => array(
                    'type'    => 'Segment',
                    'options' => array(
                        'route'    => '/[:controller][/:action[/id:id]]',
                        'constraints' => array(
                            'controller'    => '[a-zA-Z][a-zA-Z0-9_-]*',
                            'action'        => '[a-zA-Z][a-zA-Z0-9_-]*',
                            'id'            => '[0-9]+',
                        ),
                        'defaults' => array(
                        ),
                    ),
                ),

Album routing config similar...

Why this is happening? Thanks.

2

2 Answers

0
votes

Looks like it's how ZF2 works (read isActive() function in Zend\Navigation\Page\Mvc.php). Initially it checks matching of route/controller/action, but if it fails, ZF2 again check for just controller/action pair. So there are three possible ways:

  1. Open a ticket at https://github.com/zendframework/zf2/issues and wait for response.

  2. Override \Zend\Navigation\Page\Mvc.

  3. Choose different names for controllers (and don't use index name because it's default name for controller in Mvc.php).

0
votes

If you make your controller names include the the namespace then they will be unique and won't clash:

Admin\Controller\IndexController
Album\Controller\IndexController

Rather than

Index
Index