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';

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

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