What does $ route ['(: any)'] = 'pages / view / $ 1' mean? Codeigniter Router Average

In the Codeigniter documentation https://www.codeigniter.com/user_guide/tutorial/static_pages.html

I could not understand what $1 means in the expression $route['(:any)'] = 'pages/view/$1';

+6
source share
2 answers

$1 will match any group (:any) , which is really anything. Everything you add will be passed as a parameter to the view method in the pages controller.

See more details on routing with codeigniter .

+7
source

$route['(:any)'] = 'pages/view/$1'; means that everything that you type on url will go to pages/view/$1 $1 here - this is the parameter that you want to pass to the controller / method example

$route['login/(:any)'] = 'home/bacon/$1';

in this example, you tell CI that everything that is sent to login with any parameter, for example login/john , will go to your home/bacon/john (:any) , will match all strings and integers if you use (:num) , it will only match integer parameters, for example

$route['login/(':num')'] = 'home/bacon/$1'

in this configuration, you indicate that if url login has an integer after it, like login/1234 , you want it to be redirected to home/bacon/1234 , if you don’t know how many parameters you would like to go through, you can try $route['login/(:any).*'] = 'home/bacon/$1' you can read more about this at https://www.codeigniter.com/user_guide/general/routing.html

+21
source

All Articles