I'm having a question that is driving me kinda nuts right now.
I really like the way vB handles the url's and makes the navbar and I would like to be able to make the same sort of url's and navbar.
First I was looking how the url's where made so nice, so I did some research on mod_rewrite and I am able to make some nice url's, but I'm still with the question how vB handles a url like: http://www.talkphp.com/general/ and http://www.talkphp.com/general/1-example/. I know that vB (in the second case) just gets the number of the topic and shows it, no mather what is behind the number, but how does vB handle the first case ?
I had a thought that maybe vB takes 'general', looks for a title in a db and gets stuff, but then I thought, how does it handle 'tips and tricks' while the url says /tips-tricks/ . . .
The navbar was also driving my head nuts, but I now know (or actually think) that it gets a parent/child id and looks up the parents/children and then makes the navbar.
Could someone help me in how to make does url's and/or enlight me with some idea's on how to implement this easily ?
*And since we're in between the holidays, happy holidays everone =]
It probably uses what's called a slug, and descriptive name. The descriptive name can be anything, "General Information and Your Toilet" whereas the slug would be url readable (and unique), such as "general-toilet-info".
Your table schema would include this, most likely as an index used for lookups. Parse the url, get the slug, select the appropriate category information and grab your data from there.
The Following User Says Thank You to delayedinsanity For This Useful Post:
I have done this using numerous methods. The most simple for me was to simply define or in the case of a forum, create a friendly url value out of the title. In my CMS' I do the same only the administrator can define one, if not defined, create from the title.
Either way, my current CMS is MVC based, so it has been quite simple to do. For example, site.com/content/index/php would really be a call to the content.php controller, calling the index() method and passing php as a parameter.
I would then show the page that matches php as the URL value (ofcoarse upon creating, editing, etc pages I ensure I can't have conflicting results, many of the same, etc). Further more I can go another step to have site.com/content/index/php/strlen.
This is the same, but php AND strlen is passed to the index() method. If I find I have the second parameter, I will attempt to load the child based on the parent being PHP.
I know, sounds confusing but its not. You could do similar things using $_GET alone, but you will need more mod_rewrite rules to match. For example, in an older CMS I wrote before finding MVC, I used to have a component based setup. Basically, I requested an action ( $_GET['action'] ) which was used to determine the component file. If the action was content, then I would load content.php.
From here the component decided what to do, usually in the constructor or a secondary method (using switch to check for a $_GET['whatever_else']). Using that value would determine the method called, and for additional parameters I would simply call $_GET again. MVC made this MUCH, MUCH easier (you can check out Kohana Framework, Code Ignitor or MVC design patterns with PHP).
In your case, or in VB, I don't know how they do it. I've made a forum in which you would have urls such as site.com/forum/general/how-do-i-do-this.html. Again, the same principal. general is a value stored in the database under a URL field. how-do-i-do-this is a value stored in the database as well, but the topics have a forum_url field to match to ensure that the how-do-i-do-this page belongs with general.
Sorry, might sound confusing, but it's not that bad if you play with it. If you need, I can show off my database schema for the CMS/forum I am writing and it will probably click much better.