• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
want to create a url like http://www.example.com/uername

#1
[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?

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

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

#4
[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?

#5
[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

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

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

#8
[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

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

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

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


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.