Kohana 3路由和查询字符串

编程入门 行业动态 更新时间:2024-10-27 08:39:20
本文介绍了Kohana 3路由和查询字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如果我有这样的路线:

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路由和查询字符串

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

发布评论

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

>www.elefans.com

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