Routes - Codeigniter

Asked

Viewed 229 times

2

I wonder what this $ means in defining routes, for example :

route["(.*)-sid-(:num)-(:num)"] = "services/service/$2/$3";

What it represents $2and $3?

  • 1

    According to the manual: $route['products/([a-z]+)/(\d+)'] = "$1/id_$2"; URL: products/shirts/123 -> $1 = shirts e $2 = id_123. Represent the parameters of the route you set.

  • 1

    are only variables representing the ID and Function that will be passed to the url

1 answer

4


These are groupings of captured characters from a Regular Expression or RegEx.

In its case, Codeigniter can define the routes with the groupings of Regular Expressions within the parentheses, where in: $route["(.*)-sid-(:num)-(:num)"] = "services/service/$2/$3";, $2 and $3 respectively represent the groups of numeric characters (:num) and (:num) and $1 capture a group of characters if available (.*)

  • 1

    Perfect explanation, thank you!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.