URL 问题:zend navigation 将路由附加到 url - 如何修改 zend navigation 默认渲染
我重新编辑了问题以表明问题出在哪里。
嗨, 我正在使用 Zend Framework 构建一个 cms 应用程序。除了 >url 之外,一切正常。当我单击指向以下内容的链接时:
'dep/open/id/001'
我有效地到达了那里,但链接文本被附加到网址中。如果我现在将鼠标悬停在>另一个链接上,我可以在状态栏中看到:
'dep/open/id/dep/open/id/023'
等等。
我无法编辑 url,因为是 Zend_Navigation 正在渲染它们。
如何修改它?
谢谢
问题是我给 Zend_Navigation 提供了错误的 uri:
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);
}
uri 应该是:
$uri = $dep->dept_id;
我认为这可能是因为我为“dep”设置了一条路线,
$route = new Zend_Controller_Router_Route(
'dep/show/:id',
array(
'action' => 'show',
'controller' => 'dep',
'module' => 'default',
'id' => '',
),
array(
'id' => '[0-9]+'
)
);
$router->addRoute('dep', $route);
这可能是原因吗?
再次感谢
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_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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在我看来,问题在于您提供了一个相对网址:
$uri = 'dep/show/id/' 。 $dep->dept_id;
所以实际上是浏览器把你搞砸了,将那个url相对解释为当前的url。
如果您使用基本 url 前缀创建 url:
$uri = 'http://example.com/myapp/dep/show/id' 。 $dep->dept_id;
甚至:
$uri = '/myapp/dep/show/id' 。 $dep->dept_id;
那么浏览器会将它们视为绝对的(分别是 root-absolute),并且您应该处于更好的状态。
请注意,
baseUrl()
可从前端控制器获取。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.在第一次重新编辑该问题之后,我继续尝试传递给 Zend_Navigation 的路由和参数,我得出的结论是,实际上问题是我已经将“dep”路由设置为:
因此将相同的路由传递给Zend_Navigation 的 $uri 参数产生了重复问题。
似乎直到我在这里发布问题才找到解决方案
感谢大家的耐心等待
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:
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