将 URL 参数注入 Zend_Navigation 菜单 [英] Inject URL parameters into Zend_Navigation menu
问题描述
是否有人将 Zend Navigation 与需要动态参数的 URL 结合使用?
Is anyone using Zend Navigation in conjunction with URLs that require dynamic parameters?
Zend_Navigation 在处理静态路由时似乎很容易,但我想不出任何方法让它与动态 URL 参数配合使用.
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.
路线如下:
routes.editUser.route = '/users/:id/edit'
routes.editUser.defaults.controller = 'user'
routes.edutUser.defaults.action = 'edit'
在此导航中:
<pages>
<editUser>
<controller>users</controller>
<action>edit</action>
<route>editUser</route>
</editUser>
</pages>
除非我为 :id
指定默认值,否则只会在 Zend_Navigation 中引发错误.但是,如果我在构建菜单时不能注入实际的用户 ID,那对我来说是没有用的.
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.
推荐答案
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
));
}
这篇关于将 URL 参数注入 Zend_Navigation 菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!