Issues

ZF2-447: Inconsistency in 'controller' key causes error with Zend\Navigation\Page::isActive()

Issue Type: Bug Created: 2012-08-04T09:34:57.000+0000 Last Updated: 2012-10-08T20:15:02.000+0000 Status: Closed Fix version(s): Reporter: Zion Ng (kitthrng) Assignee: Frank Brückner (frosch) Tags: - Zend\Navigation

  • RouteMatch
  • Zend\Navigation\Page\Mvc
  • isActive

Related issues: Attachments:

Description

Problem getting the router, menu view helper and breadcrumbs view helper to work in sync.

Sample dump of $reqParams and $myParams at line 120 of Zend\Navigation\Page::isActive(), just before if (null !== $this->getRoute() on line 121:

<pre class="highlight">
  '__NAMESPACE__' => string 'Web\Controller' (length=14)
  'controller' => string 'Web\Controller\Tools' (length=20)
  'action' => string 'calendar' (length=8)
  '__CONTROLLER__' => string 'tools' (length=5)



<pre class="highlight">
  'controller' => string 'tools' (length=5)
  'action' => string 'calendar' (length=8)

The 'controller' key is checked to see if the page is active, which in this case fails, unless CONTROLLER is used for comparison.

<pre class="highlight">
'Home' => array(
    'label' => 'Home',
    'route' => 'web',
    'controller' => 'index',
    'action' => 'index',
),
'Calendar' => array(
    'label'  => 'Calendar',
    'route' => 'web',
    'controller' => 'tools',
    'action' => 'calendar',
),

If 'controller' for 'Calendar' is set to 'Web\Controller\Tools', isActive would work but the href generated would be /web/Web/Controller/Tools/calendar and not/web/tools/calendar. The breadcrumbs view helper detects 'Home' as the active page even though 'Calendar' is the actual active page.

<pre class="highlight">
'router' => array(
    'routes' => array(
        'web' => array(
            'type'    => 'Zend\Mvc\Router\Http\Segment',
            'options' => array(
                'route'    => '/web[/:controller][/:action]',
                'constraints' => array(
                    'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
                    'action'     => '[a-zA-Z][a-zA-Z0-9_-]*',
                ),
                'defaults' => array(
                    '__NAMESPACE__' => 'Web\Controller',
                    'controller'    => 'index',
                    'action'        => 'index',
                ),
            ),
            'may_terminate' => true,
            'child_routes' => array(
                'wildcard' => array(
                    'type' => 'Zend\Mvc\Router\Http\Wildcard',
                    'options' => array(
                        'key_value_delimiter' => '/',
                        'param_delimiter' => '/',
                    ),
                    'may_terminate' => true,
                ),
                'trailingSlash' => array(
                    'type' => 'Zend\Mvc\Router\Http\Literal',
                    'options' => array(
                        'route'    => '/',
                        'defaults' => array(
                        ),
                    ),
                ),
            ),
        ), // end web route
    ), // end routes
), // end router

The other alternative might be to create a route for each page. But if there are 10 controllers each having 5 actions, 50 routes would need to be defined?

Comments

Posted by Frank Brückner (frosch) on 2012-09-18T20:32:37.000+0000

Code tags added.

Posted by Frank Brückner (frosch) on 2012-09-18T20:55:26.000+0000

I will write an unit test to check your router and navigation configuration.

Posted by Ralph Schindler (ralph) on 2012-10-08T20:15:02.000+0000

This issue has been closed on Jira and moved to GitHub for issue tracking. To continue following the resolution of this issues, please visit: https://github.com/zendframework/zf2/issues/2515

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts