简体   繁体   English

CodeIgniter路由差异?

[英]CodeIgniter Routing Difference?

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: 一个快速的问题,我似乎找不到与CI中路由相关的任何答案-全局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. 我的路由没有任何问题,而且两者看起来都一样,但是只是想知道一种方法是否比另一种更好。

OK, after digging into the Router class it seems that (:any) is a CodeIgniter expression which gets converted into the regex expression: 好的,深入研究Router类之后,似乎(:any)是一个CodeIgniter表达式,该表达式被转换为regex表达式:

.+

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. +匹配上一个字符1次或更多次,*匹配上一个字符0次或更多次。 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. 希望对其他人也有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM