简体   繁体   中英

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:

$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:

.+

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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