views:

450

answers:

1

I use Navigation component for site menus. I also use let zend figure-out the selected menu item from request parameters - I guess this is done automatically. The only problem is, that for this to work, action and controller have to be specified in navigation configuration for every node. This also means that when zend generates links from route, action and controller information to appended to the generated link automatically.

Anyone had the same problem?

Zend manual section, explaining the Mvc navigation page features.

Example:

some route defined in bootstrap:

 $router->addRoute('user_profile_tab', new Zend_Controller_Router_Route(
            'profil/:user/:location/:tab/*',
            array(
                'action'     => 'profile',
                'controller' => 'user',
                'user'  => ($user ? $user->id : 0), //change later
                'location'  => 0 //inject appropriate value later
            )
        ));

navigation container object:

$container = .....
......,
array(
       'label' => tr('Privileges'),
        'id'    => 'user-profile-perms',
    'type' => 'Zulu_Navigation_Page',
    'controller' => 'user',
    'action' => 'profile',
    'route'=> 'user_profile_tab',
        'params' => array('tab'=>Main_Lib_Common::NAVI_USER_TAB_PERMS)
)
);

the result when using

$page = $container->getById('user-profile-perms');
$page->href;

http://www.example.com/profil/1/0/3/controller/user/action/profile

WHY action and controler params in the navigation container object you ask. The $page->isActive() check needs this data to make a perfect match.

THE FIX:

extend mvc navigation page and provide an alternative getHref() method ... one that removes action, controller and module params when a route does not define them.

A: 

I have done this to fix this weird behaviour:

  • extend mvc navigation page
  • provide an alternative getHref() method
  • check for routes, not having action , controller and module parameters and remove them from params array before href generation.

This way the isActive matching will still work, as we didnt modify the route or navigation nodes in any way.

gregor
Perhaps you should file a bug-report as this surely isn't the intended behaviour: http://framework.zend.com/issues
Stefan Gehrig