Inject URL parameters into Zend_Navigation menu

跟風遠走 提交于 2019-12-10 10:49:34

问题


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:


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
    ));
}


来源:https://stackoverflow.com/questions/2806042/inject-url-parameters-into-zend-navigation-menu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!