2

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 Answer 1

5

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
    ));
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.