I want to call a function from a controller, my_controller, passing in two arguments to some_method: first argument is the slug (ie. some-website-slug); second, a number. This is what I am trying:
$route['my_controller/([a-z0-9]+(-[a-z0-9]+)*)/(:num)'] = "my_controller/some_method/$1/$2";
The problem is, it always passes in "-slug" (ie. the last part of the slug string) instead of the number. So for example with
base_url/my_controller/some-uri-slug/2
It will pass in "-slug" instead of the number 2. Is there something wrong with the regex or is it CI?
Your Regex has two pairs of ()
, so (:num)
is actually at $3
not $2
.