• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
URI Routing: (:any) or (:segment)?

#1
Question 
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).
It is easier to search the internet than posting a question. So, yes, I am asking because I did not find the answer anywhere else.
Reply

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

#3
(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).
It is easier to search the internet than posting a question. So, yes, I am asking because I did not find the answer anywhere else.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.