将URL参数注入Zend_Navigation菜单

Bry*_* M. 2 php zend-framework

是否有人将Zend Navigation与需要动态参数的URL结合使用?

在处理静态路由时,Zend_Navigation看起来非常简单,但我无法想办法让它与动态URL参数一起使用.

像这样的路线:

routes.editUser.route = '/users/:id/edit'
routes.editUser.defaults.controller = 'user'
routes.edutUser.defaults.action = 'edit'
Run Code Online (Sandbox Code Playgroud)

在此导航中:

<pages>
  <editUser>
    <controller>users</controller>
    <action>edit</action>
    <route>editUser</route>
  </editUser>
</pages>
Run Code Online (Sandbox Code Playgroud)

只是在Zend_Navigation中引发错误,除非我指定了默认值:id.但是,如果在构造菜单时无法注入实际的用户ID,对我来说没用.

有一种直截了当的方法吗?谢谢.

Bal*_*an1 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
    ));
}
Run Code Online (Sandbox Code Playgroud)