Welcome Guest, Not a member yet? Register   Sign In
Pass ID, display title in URL
#1

[eluser]Kamy[/eluser]
Hi:

I'm new to CI, so this question might have been answered already.
I searched the forum before posting.

Basically what I need to do is after passing the articleID to retrieve the info, instead of a url like: http://www.mysite.com/article/123

I'd like the url to be http://www.mysite.com/article/article-title

I've already setup all the code that passed the id and displays data properly.

please help

thanks

Kamy
#2

[eluser]johnpeace[/eluser]
So...

All you need to do is rewrite your select query so that it selects the article by title instead of by ID....then pass the title in the URL, right?

It might take a little string manipulation to make sure the titles are URL safe, but that's easy.
#3

[eluser]Kamy[/eluser]
passing title in the query is not a good practice, as it includes utf chars and spaces
#4

[eluser]smilie[/eluser]
Kamy, so what you are looking for is to see title in the URL, but to search based on the ID.
I do not think this will be easy.

CI considers everything behind controller name to be variable to be used in the controller.
Only thing that comes to my mind is following:

When calling controller, always to use forms. Meaning:
Page A -> index page (for example).
From there user clicks on a link which takes him to:
http://www.mysite.com/article/article-title
'Underwater' link is part of a form, with hidden article ID field.

In the controller, you simply 'ignore' article title variable and work with $this->input->post('articleid').

This way, user will see article title in URL, but all code will be done through article ID.

Maybe there are other ways, but I do not know them.

Hope this helps.

Regards,
Smilie
#5

[eluser]CroNiX[/eluser]
You can always pass both. I've noticed vBulletin is now doing this for SEO purposes. Just split on '-' and grab first value to get ID.

Example URL using 92 as the index:
http://www.vbulletin.com/forum/forumdisp...ort-System
#6

[eluser]CroNiX[/eluser]
Another thing I do sometimes is to have the ID in a hidden form variable which gets passed and use the URL for URL friendly things. Obviously won't work for pages that don't use forms.
#7

[eluser]Kamy[/eluser]
Looking at CI docs, it seems url_title() is the way to go.
However I don't have any experience with that.

I give it a go, any ideas?




Theme © iAndrew 2016 - Forum software by © MyBB