• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Clean URL question

Hi I am new to the PHP/CodeIgniter scene.

My problem lies with an efficient way to retrieve data out a database, without sending the id in the URL and after using url_title(); I convert my article title to 'this-is-my-article'

so my URLs currently are http://localhost/mysite/index.php/view/this-is-my-article.

Is there away to retrieve the data using the id without sending it in the URL. I ultimately want to be able to click on an article's title and then using a clear URL with no ID number be able to display more fields from the database. The only other way that I can see to do this is to take each article title out the data convert using url_title(); and compare it to the url using the URI segment function. I worried that this can cause long delays.

Help would be appreciated.

[eluser]Colin Williams[/eluser]
Your system should still be based off of an ID, but essentially what you're wanting to do is create aliases for these IDs. I would store these aliases in a separate database table, which essentially says http://localhost/mysite/index.php/view/this-is-my-article is an alias for, say, http://localhost/mysite/index.php/content/view/1 (1 being the ID of the content in the database).

You could then reroute 'view/:any' to the Content controller. Then create something like a get_by_alias() method in your model that looks up the alias (extracts it from the URL) then JOINs your content table on whatever ID is stored in relation to given alias.

[eluser]Pascal Kriete[/eluser]
I disagree with Colin on this one.

Just make a new field, let's call it permalink, and then query on that the same way you do with ids. You will still have auto-incrementing ids, for foreign keys and such.

The new field should be populated when you create a new post.

That way all your major processing is done when you insert and not when you get.

[eluser]Colin Williams[/eluser]
That will work for sure, inparo, and is probably a bit better in a small scale implementation like this.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

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