February 23, 2012

Codeigniter Route to accept dynamic values

Question by mrN

I am trying to create a router which will take a dynamic value and forward it to the actual route. In normal case it would be like

$route['login'] = 'auth/login';

It is possible to catch a parameter before the login in the above parameter and pass it to as the first parameter to the actual route ? like

$route['^(.+)/login$'] = "$1/user/login";

Answer by Starx

Check out the documentation[docs]. There is a very easy way to do this.

$route['(:any)/login'] = '$1/auth/login';
...

Please fill the form - I will response as fast as I can!