Enter URL parameters into Zend_Navigation menu
Does anyone use Zend Navigation in conjunction with URLs that require dynamic parameters?
Zend_Navigation seems to be very lightweight when dealing with static routes, but I can't figure out how it would play well with dynamic URL parameters.
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>
It just throws an error in Zend_Navigation if I don't specify a default for :id
. However, it is useless to me if I cannot enter the actual user ID when creating the menu.
Is there an easy way to do this? Thanks.
+2
a source to share
1 answer
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
));
}
+5
a source to share