Welcome Guest, Not a member yet? Register   Sign In
URL Rewrite help for doing changes in current rewrite -- VERY URGENT
#1

[eluser]Unknown[/eluser]
Hi,

My Current URL display is:

http://sitename.com/personality/25

This is done by the route facility given in framework.

Where 25 is the DB Id of that user. Now I want to display name but don't want to change Id because that Id is used in every page for reference.

So the new URL is:

http://sitename.com/personality/sandy

But in background I should the get Id ref as i am fetching details from DB.

So please any body advise me.
#2

[eluser]barbazul[/eluser]
unless you only only want to do this for a couple of hard-coded users you shoud try using the name to fetch the users from the DB instead of the ID.
That means that you should probably create an index on the "name" field and make it unique.

you could probably route your request with something like:

Code:
$routes["personality/(\\d+)"] = "personality/users_by_id/$1";
$routes["personality/(\\w+)"] = "personality/users_by_name/$1";

that way you'll lose the ID reference but you'll have the name that you can use.

If you want to be able to always use the id to search the database, you can build a map of name->id and store it somewhere (like a text file) on the server. Each time you create a new user you add it to the map and when the url gets called by name you can easily retrieve the ID. I cannot assure this will perform better than searching the DB using the name. Probably not.
#3

[eluser]elvix[/eluser]
Why don't you just add the name to the end of the url, leaving ID intact?

So you'd have something like: http://sitename.com/personality/25/sandy

CI will ignore the last segment, but your users & engines will see it.
#4

[eluser]Unknown[/eluser]
Hi elvix,

Thanks buddy for alternate solution. It worked. :-)

cheers
Sandy
#5

[eluser]MMCCQQ[/eluser]
eyy!


i got a similar problem,example my actual url is http://somethinh.com/class/function/

i want something like http://somethinh.com//function/




Theme © iAndrew 2016 - Forum software by © MyBB