Welcome Guest, Not a member yet? Register   Sign In
URL routing-rewrite issue
#9

[eluser]Pascal Kriete[/eluser]
[quote author="Animas" date="1207501924"]Can't there be duplicate title? But id will be unique. It would be nice if you could suggest me what changes I should do inside this code.[/quote]

Yes the id will be unique. But if a user calls up www.example.com/blog/that_bbcode_tutorial and you have two posts called 'That bbcode tutorial' you won't know which one they want.

There is no point to using both an id and a title. It adds nothing to the granularity of the selection. An id is unique, so that by itself is enough. If you want the title, then you have to work it so it can do the job by itself as well. The route you suggested would have to map the title to an id. If you can map the title to the id, you don't need the id in your url anymore.

Let's dig into that code now. It looks correct as it is, so we'll just work on figuring out where it fails.

My suggestion would be to ditch all the uppercases and spaces in the title, you can do that when inserting:
Code:
// $orig_title comes from a form submit or whatever..makes no difference
$clean_title = str_replace(' ', '-', $orig_title);
$clean_title = strtolower($clean_title);

// Insert this and the post body into the db, (and probably an auto incrementing id)

Now to get this back, the user will need to enter that clean url. So if we called our post 'That GreaT adventUrE', the url segement has to be 'that-great-adventure' regardless.

To get it back:
Code:
// Use the name in the url to call the db (just like you're doing now)
$clean_title = //whatever will give us the title

$title = str_replace('-', ' ', $clean_title);
$title = ucwords($title);

If something isn't coming out as expected the first thing to do is print_r the array/object to see if the keys are set at all.

This should ensure that your database selections don't fail because of case issues and odd characters. It doesn't solve the duplicate titles yet. One thing to do would be to add a number to the end of the title if it already exists.


Messages In This Thread
URL routing-rewrite issue - by El Forum - 04-06-2008, 12:39 AM
URL routing-rewrite issue - by El Forum - 04-06-2008, 02:44 AM
URL routing-rewrite issue - by El Forum - 04-06-2008, 03:25 AM
URL routing-rewrite issue - by El Forum - 04-06-2008, 05:44 AM
URL routing-rewrite issue - by El Forum - 04-06-2008, 05:50 AM
URL routing-rewrite issue - by El Forum - 04-06-2008, 06:00 AM
URL routing-rewrite issue - by El Forum - 04-06-2008, 06:03 AM
URL routing-rewrite issue - by El Forum - 04-06-2008, 06:12 AM
URL routing-rewrite issue - by El Forum - 04-06-2008, 07:11 AM
URL routing-rewrite issue - by El Forum - 04-06-2008, 07:50 AM



Theme © iAndrew 2016 - Forum software by © MyBB