zend框架url生成问题
我在使用 zf 版本 1.11.6 生成简单的 url 时遇到一些困难。我正在为此使用 url 帮助器。
示例:
$this->url(array('controller' => 'index', 'action' => 'index'))
$this->url(array ('controller' => 'index', 'action' => 'view', 'id' => 1))
结果:
domain.com/index/index/id/1
domain.com/index/view/id/1
正如你所看到的,问题是连我都没有指定第一条规则的任何 id 参数,生成的 url 都包含它。 action
也会发生这种情况。如果我让第一条规则不带 action
参数,则会生成具有 view
值的规则(而不是使用 index
的默认值) 。假设我可以接受 action
的事情,但是当涉及到其他参数时,这是荒谬的。
即使我在控制器中使用第一个规则并在视图文件中使用第二个规则,也会发生这种情况。
对此有什么想法吗?谢谢。
I'm having some difficulties generating simple urls with zf version 1.11.6. I'm using the url helper for this.
Example:
$this->url(array('controller' => 'index', 'action' => 'index'))
$this->url(array('controller' => 'index', 'action' => 'view', 'id' => 1))
Result:
domain.com/index/index/id/1
domain.com/index/view/id/1
As you can see, the problem is that even I have not specified any id
param to the first rule, the generated url contains it. This happens also with action
. If I let the first rule without the action
parameter, it will be generated having the view
value (instead of using the default value of index
). Let's say that I can live with the action
thing, but this is absurd when it comes to the other parameters.
This happens even though I use the first rule inside my controller and the second one inside a view file.
Any thoughts on this ? Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
现在看到它很容易。
结果是
域名.com
现在检查这个
结果
domain.com/detail/14
您应该在不希望有 id 值的地方提供空数组
Now see its quite easy.
Result in
domain.com
and now chekc this
Results in
domain.com/detail/14
You should provide empty array where you dont want to have id value
我假设您收到此错误是因为默认路由以某种方式被删除。请检查项目中某处是否执行了
removeDefaultRoutes
方法。I'm assuming you're getting this error because the default routes are being deleted somehow. Please, check if there are any execution of the
removeDefaultRoutes
method somewhere in your project.