CodeIgniter Forums

Full Version: want to create a url like http://www.example.com/uername
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2

El Forum

[eluser]Rayhan[/eluser]
I want to create a page for the users to view their profile [http://www.example.com/uername] similar to facebook.com after creating their accounts. What would be the best way to achieve that?

El Forum

[eluser]Rayhan[/eluser]
Any ideas please?

El Forum

[eluser]boltsabre[/eluser]
so you waited 7 minutes before bumping your own post...
http://ellislab.com/codeigniter/user-gui...uting.html

El Forum

[eluser]Rayhan[/eluser]
cool... but haven't got a clue from there...
This is what I have now....
http://www.example.com/user/profile/12 and now I want it to be http://www.example.com/12

I looked at the codeigniter guide for routing and set up new route similar to this one
$route['(:num)'] = "user/profile/$1"; - not working. This whole routing business seem very tricky to me. Can you please explain it further?

El Forum

[eluser]boltsabre[/eluser]
not working... any error messages? what's not working

$route[(:num)] = "user/profile/$1";

I would have expected that to work... is your profile function accepting variables? The $1 is a function variable. For example
Code:
public function profile($user_id){

}

If that's not the problem, try this rule, does it work?
$route[u/(:num)] = "user/profile/$1";

I don't have a great deal of experience with routing, perhaps it needs actual 'controller' to 'controller' mapping (for want of a better expression), what I mean is, maybe the first parameter cannot actually be a variable (number in your case), you may have to settle for a url that looks like :domain.com/u/11234

El Forum

[eluser]InsiteFX[/eluser]
When using a route like that it needs to be the very last route in the list.

El Forum

[eluser]Rayhan[/eluser]
it is the last one...

El Forum

[eluser]Rayhan[/eluser]
[quote author="boltsabre" date="1340205049"]not working... any error messages? what's not working

$route[(:num)] = "user/profile/$1";

I would have expected that to work... is your profile function accepting variables? The $1 is a function variable. For example
Code:
public function profile($user_id){

}

If that's not the problem, try this rule, does it work?
$route[u/(:num)] = "user/profile/$1";

I don't have a great deal of experience with routing, perhaps it needs actual 'controller' to 'controller' mapping (for want of a better expression), what I mean is, maybe the first parameter cannot actually be a variable (number in your case), you may have to settle for a url that looks like :domain.com/u/11234[/quote]

I will give it a go....thanks

El Forum

[eluser]Rayhan[/eluser]
I have got some info about mod_rewrite and will try this too

El Forum

[eluser]InsiteFX[/eluser]
Code:
$route['*(:any)'] = 'user/profile/$1';

// May need to change the first number.
$profie = $this->uri->segment(1, 0);
Pages: 1 2