CodeIgniter Forums
How do I work with all this data without making my URLs too long? - 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: How do I work with all this data without making my URLs too long? (/showthread.php?tid=10767)



How do I work with all this data without making my URLs too long? - El Forum - 08-12-2008

[eluser]KeyStroke[/eluser]
Hi,

I basically have a section of my site where the items can be viewed depending on their country and city, and then the results can be sorted by data, number of views or whatever else.

I don't want to end up with URLs looking like this:
Quote:http://example.com/controller/function/country/city/sort_by_date/

Because it's very linear and not flexible in case I needed to add something else in the future.

So, how could I overcome this limitation?

If it can't be overcome, then is there a way I can enable GET variables for this section (i.e: Controller) for my site?


Your help is much appreciated


How do I work with all this data without making my URLs too long? - El Forum - 08-12-2008

[eluser]xwero[/eluser]
Using GET makes an even longer string, or am i missing something?
Quote:http://example.com/controller/function/?country=country&city=city&sort_by_date=date



How do I work with all this data without making my URLs too long? - El Forum - 08-12-2008

[eluser]KeyStroke[/eluser]
Yea it would look long and ugly, but at least I'll get to add or remove variables without worrying about breaking old links.


How do I work with all this data without making my URLs too long? - El Forum - 08-12-2008

[eluser]mdowns[/eluser]
You could have the page be:

http://example.com/controller/function

Then add some UI elements on the page to select the country, city, and sort type. Use AJAX to query the data and generate the html. Then simply display the result.


How do I work with all this data without making my URLs too long? - El Forum - 08-12-2008

[eluser]SpooF[/eluser]
mdowns solution is probably best, but if you dont want to use ajax you can always make your own "query string".

I did this for one of my projects. My uri segment looked like this:

Code:
manufacturer.3-user.3-status.1

This broke down to:

Code:
manufacturer=3
user=2
status=1



How do I work with all this data without making my URLs too long? - El Forum - 08-12-2008

[eluser]eilrahc[/eluser]
http://example.com/controller/function/country/city/sort_by_date/

I don't see anything particularly wrong with this, actually. As long as you've thought it through and the organization makes sense, there shouldn't be a good reason not to do this unless you're delibeately planning to change it in the future. If it comes up that it *must* be changed, there are numerous ways to redirect to the new content (mod_rewrite, CI routing, or redirecting within the URL itself). Or you could use a redirection technique right in the beginning, by using links like:

http://example.com/searchcity/12345


How do I work with all this data without making my URLs too long? - El Forum - 08-12-2008

[eluser]Colin Williams[/eluser]
Use the uri_to_assoc() method of the URI class to get key/value pairs from the URI


How do I work with all this data without making my URLs too long? - El Forum - 08-12-2008

[eluser]Tom Glover[/eluser]
[quote author="Colin Williams" date="1218596863"]Use the uri_to_assoc() method of the URI class to get key/value pairs from the URI[/quote]

That could make it simpler at the expense of doubling the length of your url's