Url problem: zend navigation appends routes to url - How to modify zend navigation default rendering
I have reedited the question to show where was the problem.
Hi, I'm building an cms application with Zend Framework. Everything works fine except for the >urls. When I click on a link that points to:
'dep/open/id/001'
I effectively get there but the link text is appended to the url. If I now hover on >another link I can see in the status bar:
'dep/open/id/dep/open/id/023'
and so on.
I can't edit the urls because it's Zend_Navigation which is rendering them.
How can I modify this?
Thanks
The problem was that I was giving Zend_Navigation wrong uris:
public function renderAction()
{
...
//THIS IS WRONG:
$uri = 'dep/show/id/' . $dep->dept_id;
...
$itemArray[] = array(
'label' =>$label,
'uri' => $uri
);
}
$container = new Zend_Navigation($itemArray);
$this->view->navigation()->setContainer($container);
}
The uri should be :
$uri = $dep->dept_id;
I think this may be because I have set a route for 'dep'
$route = new Zend_开发者_JS百科Controller_Router_Route(
'dep/show/:id',
array(
'action' => 'show',
'controller' => 'dep',
'module' => 'default',
'id' => '',
),
array(
'id' => '[0-9]+'
)
);
$router->addRoute('dep', $route);
Could that be the reason?
Thanks again
Looks to me like the issue is that you are supplying a relative url:
$uri = 'dep/show/id/' . $dep->dept_id;
So it's actually the browser that is screwing you up, interpreting that url relative to the current url.
If you create your url with a base url prefix:
$uri = 'http://example.com/myapp/dep/show/id' . $dep->dept_id;
or even:
$uri = '/myapp/dep/show/id' . $dep->dept_id;
then the browser will treat those as absolute (respectively root-absolute) and you should be in better shape.
Note that the baseUrl()
is available from the front controller.
After the first reedition of the question I have continued experimenting with the routes and the parameters passed to Zend_Navigation and I have come to the coclusion that actually the problem was that I had already set the 'dep' route to:
'/dep/show/id'
so passing the same route in the $uri parameter to Zend_Navigation produced the duplication problem.
It seems that I don't find solutions until I post questions here Thank you all for your patience
精彩评论