如果我有这样的路线:
Route::set('test', 'test') ->defaults(array( 'controller' => 'test', 'action' => 'index' ));我假设只会发送网址mysite/test或mysite/test/到此路由,其他任何内容都将发送到默认路由,如果有,则将捕获所有路由。但是,您可以附加任何查询字符串,它仍然有效。例如,以下任何一种方法都可以正常工作:
I assumed that only the url mysite/test or mysite/test/ would be sent to this route and anything else would be sent to the default route, or a catch all route if you have one. However, you can tack on any query strings and it will still be valid. For example any of these would work:
mysite/test/?abc mysite/test/?abc=123 mysite/test/?abc=123&blabla=lala您基本上想要的任何东西。如何进行设置,以使测试路由与查询字符串的网址不匹配?另一个示例可能是:
Anything you want basically. How can I set it so that the test route doesn't match the URL with query strings? Another example might be this:
Route::set('test', 'test(/?order=<order>)', array('order' => 'title|date|author')) ->defaults(array( 'controller' => 'test', 'action' => 'index' 'order' => 'title' ));在此示例中,我假设唯一匹配此路由的URL是:
In this example, I would assume the only URLs to match this route would be:
mysite/test/?order=title mysite/test/?order=date mysite/test/?order=author但是像以前一样,您可以添加任何其他查询字符串您想要的。
But like before, you can just add on any other query string you want.
是否有任何方法可以将这些无效的查询字符串传递到捕获所有路由,并将它们发送到404页面?还是我真的必须检查所有控制器并检查$ _GET并确保它们确实存在?
Is there any way to have these invalid query strings pass to the catch all route where they will be sent to a 404 page? Or do I literally have to go through all my controllers and perform a check on the $_GET and make sure they actually exist?
推荐答案您不应使用路由来访问查询参数。
You're not supposed to access query parameters using your routes.
路由与查询字符串完全隔离,请勿尝试使用它们,因为您将使用mod_rewrite。要访问查询参数,您应该使用:
Routes are totally isolated from the query string, don't try to use them as you'd use mod_rewrite. To access query params you should use:
$order = $this->request->query('order');更多推荐
Kohana 3路由和查询字符串
发布评论