CodeIgniter 路由差异?

发布于 2024-10-11 04:11:17 字数 239 浏览 2 评论 0原文

一个简单的问题,我似乎无法找到与 CI 中的路由有关的任何地方的答案 - 全局包罗万象之间是否有任何真正的区别:

$route['(.*)'] = 'controller';

$route['(:any)'] = 'controller';

的路由没有任何问题,并且似乎都可以工作相同,但只是想知道一种方法是否比另一种更好。

A quick question, that I can't seem to find the answer to anywhere to do with routing in CI - is there any real difference between the global catch all:

$route['(.*)'] = 'controller';

and

$route['(:any)'] = 'controller';

I don't have any problems with my routing and either seems to work the same, but was just wondering if one way was better than the other.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

祁梦 2024-10-18 04:11:17

好的,在深入研究 Router 类之后,似乎 (:any) 是一个 CodeIgniter 表达式,它被转换为正则表达式:

.+

这与使用 (.*) 不同,后者当然是一个正则表达式。因此,区别在于:

.+

.*

+ 匹配前一个字符 1 次或多次,而 * 匹配前一个字符 0 次或多次。鉴于前一个字符是 . (任何字符),这在使用它的上下文中本质上意味着相同的事情。希望这对其他人也有帮助。

OK, after digging into the Router class it seems that (:any) is a CodeIgniter expression which gets converted into the regex expression:

.+

This is different to using (.*) which is of course a regex expression. So the difference therefore is between:

.+

and

.*

The + matches the previous character 1 or more times, whereas * matches the previous character 0 or more times. Given the previous character is . (any character), this essentially means the same thing in the context it's being used. Hope that's helpful for somebody else too.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文