CodeIgniter 路由差异?
一个简单的问题,我似乎无法找到与 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,在深入研究 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.