Zend Framework 2,只有路由有子路由时,查询路由才会失败(Zend Framework 2, route with query fails only if route has child

编程入门 行业动态 更新时间:2024-10-20 07:53:27
Zend Framework 2,只有路由有子路由时,查询路由才会失败(Zend Framework 2, route with query fails only if route has child routes)

从2.1.4开始,不推荐使用Query路由,我将这样路由到我的博客:

'cro-blog' => array( 'type' => 'Literal', 'options' => array( 'route' => '/blog', 'defaults' => array( 'controller' => 'CroBlog\BlogController', 'action' => 'index', ), ), ),

并链接到像/blog?p=x这样的页面/blog?p=x其中x是页码。 在我添加子路由之前,这非常有效。 链接到/blog仍然有效,但链接到页面会产生404(更具体的'请求的URL无法通过路由匹配'。)。 这是我目前的设置:

'cro-blog' => array( 'type' => 'Literal', 'options' => array( 'route' => '/blog', 'defaults' => array( 'controller' => 'CroBlog\BlogController', 'action' => 'index', ), ), 'may_terminate' => true, 'child_routes' => array( 'post' => array( 'type' => 'Segment', 'options' => array( 'route' => '/:slug', 'constraints' => array( 'slug' => '[a-zA-Z][a-zA-Z0-9_-]*', ), 'defaults' => array( 'action' => 'post', ), ), ), ), ),

我正在使用Segment子路由,但Literal子路由存在同样的问题。

有什么方法可以保持页面查询和子路由?

Since 2.1.4 the Query route is deprecated, I'm routing to my blog like this:

'cro-blog' => array( 'type' => 'Literal', 'options' => array( 'route' => '/blog', 'defaults' => array( 'controller' => 'CroBlog\BlogController', 'action' => 'index', ), ), ),

And link to pages like /blog?p=x where x is the page number. This works perfectly until I add a child route. Linking to /blog still works but linking to pages give a 404 (more specific 'The requested URL could not be matched by routing.'). This is my current setup:

'cro-blog' => array( 'type' => 'Literal', 'options' => array( 'route' => '/blog', 'defaults' => array( 'controller' => 'CroBlog\BlogController', 'action' => 'index', ), ), 'may_terminate' => true, 'child_routes' => array( 'post' => array( 'type' => 'Segment', 'options' => array( 'route' => '/:slug', 'constraints' => array( 'slug' => '[a-zA-Z][a-zA-Z0-9_-]*', ), 'defaults' => array( 'action' => 'post', ), ), ), ), ),

I'm using a Segment child route but the same problem exists with a Literal child route.

Any way to keep the page query and the child routes?

最满意答案

这解决了。 如果有人遇到同样的问题,这对我有用。

清除所有缓存(EdpSuperluminal,APC等) 删除Zend库 在没有Zend库的情况下运行你的应用程序(当然会给出很多错误,但这对我来说似乎至关重要) 重新安装Zend库 再次运行您的应用程序

我安装了2.1.5dev并解决了这个问题。 想要确定它是否是一个错误,所以再次尝试2.1.4并且问题仍然是固定的。 所以这是我的结论。 缓存可能是一件奇怪的事情。

编辑过早地跳到(错误的)结论。 解雇了Zend Studio 10,现在再次出现问题。 我认为Zend Studio 10正在恢复一些文件(并不是所有文件,因为查询路由确实被标记为已弃用)。 不过,考虑到这个解决了,只需找到一种方法告诉Zend Studio 10使用2.1.4。 谢谢!

This is solved. If anyone experiences the same issues, this is what worked for me.

Clear all cache (EdpSuperluminal, APC etc.) Remove Zend library Run your application without Zend library (giving loads of errors of course, but this seemed crucial to me to make it work) Re-install Zend library Run your application again

I installed 2.1.5dev and it fixed the issue. Wanted to make sure whether it was a bug or not so tried again with 2.1.4 and the issue was still fixed. So this is my conclusion. Cache can be a weird thing.

Edit Jumped to (the wrong) conclusions too soon. Fired up Zend Studio 10 and now it bugs again. I think Zend Studio 10 is reverting some files (not all since Query route did got marked as deprecated). Still, consider this solved, just need to find a way to tell Zend Studio 10 to use 2.1.4. Thanks!

更多推荐

本文发布于:2023-07-25 05:40:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1256773.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:路由   才会   Zend   Framework   route

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!