CodeIgniter Forums
URI Routing: (:any) or (:segment)? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forum-28.html)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forum-30.html)
+--- Thread: URI Routing: (:any) or (:segment)? (/thread-76374.html)



URI Routing: (:any) or (:segment)? - elserra - 05-06-2020

Hi there,

I don't really understand the difference between (:any) and (:segment). The docs say that the placeholder (:any) "will match all characters from that point to the end of the URI. This may include multiple URI segments." and that the placeholder (:segment) "will match any character except for a forward slash (/) restricting the result to a single segment."


PHP Code:
URI = <baseurl>/part1/part2/part3

$routes
->group('part1', function($routes){
    $routes->get'(:placeholder)'Controller::index/$1)
}); 

What I understand from the docs:
a. (:placeholder) == (:any) --> $1 = 'part2/part3'
b. (:placeholder) == (:segment) --> $1 = 'part2'

What happens:
c. (:placeholder) == (:any) --> $1 = 'part2', $2= 'part3', and so on...
d. (:placeholder) == (:segment) --> $1 = 'part3' and tries to find Method 'part2' in a controller called 'part1'. (This I am not sure as I could not reproduce it)

I also noticed that the behaviour of (:any) and (.+) is the same, although the docs explicitly say that "With regular expressions, you can also catch a segment containing a forward slash (‘/’), which would usually represent the delimiter between multiple segments."

How can I make a. happen? I want to return everything what is stored in another folder (like ./css/pretty.css, ./index.html, /js/somefolder/some.js).


RE: URI Routing: (:any) or (:segment)? - jreklund - 05-06-2020

Hi, there are code examples here to get all parameters as an array or complete segment.
https://forum.codeigniter.com/thread-75815.html


RE: URI Routing: (:any) or (:segment)? - elserra - 05-07-2020

(05-06-2020, 11:19 PM)jreklund Wrote: Hi, there are code examples here to get all parameters as an array or complete segment.
https://forum.codeigniter.com/thread-75815.html
Thanks a lot, that's it (I hope).