March 20, 2012

create a dynamic url in codeigniter like facebook

Question by Nisha haridas

I need to create a dynamic url in codeigniter like the facebook application. Is it possible to create such url using the codeigniter framework?
eg:
1. www.facebook.com/nisha
2. www.facebook.com/dev

Answer by Starx

Its pretty easy to setup this by the use of routes. Read their routing guide

$route['([a-zA-Z]+)'] = "controller/user/$1";

However, if their is only one way of accessing the website, is like domain.com/username then its ok, otherwise, this will prove be a hard catch on the long run. On that case, limit the Route to a limited scope like

$route['users/([a-zA-Z]+)'] = "controller/user/$1";

This will help in the extending the system in numerous way

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!