Welcome Guest, Not a member yet? Register   Sign In
URI Routing: (:any) or (:segment)?
#1
Question 
(This post was last modified: 05-06-2020, 10:54 PM by jreklund.)

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).
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).
Reply




Theme © iAndrew 2016 - Forum software by © MyBB