CodeIgniter Forums
Creating Clean URLS - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Creating Clean URLS (/showthread.php?tid=17612)



Creating Clean URLS - El Forum - 04-09-2009

[eluser]macleodjb[/eluser]
I have an older article website that i want to convert over with codeigniter. My old urls are based off of the category and subcategory like this.

www.example.com/business
www.example.com/business/technology


if business if shown if will get all articles in that category.

Can this be done using a route? or is there a better way of doing it?


Creating Clean URLS - El Forum - 04-09-2009

[eluser]Alexander Obenauer[/eluser]
just make your controllers the categories.

Example: you have a controller business.

the index function will call a view and send it all of the articles. the technology function will call a view and send it only the tech articles.


Creating Clean URLS - El Forum - 04-09-2009

[eluser]macleodjb[/eluser]
Thanks but that's not the answer i was looking for. What you're telling me is that i should have a controller for each category on my site, all with the same code inside but a different name. So if i have 200 categories i will have 200 controllers, and if i want to make an edit to how it is displayed i have to edit 200 files individually. I'm sorry but that method doesn't seem very prudent.

If there is not another way to do this then i'll leave it alone.


Creating Clean URLS - El Forum - 04-09-2009

[eluser]Alexander Obenauer[/eluser]
I did not realize you may have so many categories. Please be specific next time. Also, changing it would just be changing the view file they all call.

Anyways, I would just use .htaccess to rerout /categoryname to be /controller/function/categoryname and grab the 3rd segment and fourth for subcat.