views:

353

answers:

1

Is anyone using Zend Navigation in conjunction with URLs that require dynamic parameters?

Zend_Navigation seems really easy when dealing with static routes, but I can't figure out any way to make it play nice with dynamic URL parameters.

A route like:

routes.editUser.route = '/users/:id/edit'
routes.editUser.defaults.controller = 'user'
routes.edutUser.defaults.action = 'edit'

In this navigation:

<pages>
  <editUser>
    <controller>users</controller>
    <action>edit</action>
    <route>editUser</route>
  </editUser>
</pages>

Just throws an error in Zend_Navigation unless I specify a default value for :id. However, it is no use to me if I can't inject the actual user id when the menu is constructed.

Is there a straightforward way to do this? Thanks.

+1  A: 

resources.navigation.pages.profile.params_id = "USER_ID"

// Looks for any navigation pages requiring user information and injects it
$pages = $this->getContainer()->findAllBy('params_id', 'USER_ID');
foreach($pages as &$page){
    $page->setParams(array(
        'id'=>$user->id,
        'username'=>$user->username
    ));
}
Ballsacian1
Clever way to do it. Thanks!
Bryan M.