Welcome Guest, Not a member yet? Register   Sign In
abandoning GET vars?
#1

[eluser]Unknown[/eluser]
Hello all,

I have a question about using CI that I hope I can state simply. I have built numerous web applications that use GET vars extensively, and I am trying to understand how a similar application would work under CI - using it out of the box, without enabling the GET vars feature.

Imagine a list view of financial forecast items for a given month. You can filter this view by office or by department, by salesperson, or combinations of these. You can also click on next month or previous month, and the filter must stick ( if you are looking at the Chicago office, you will still only see Chicago after clicking the "next month" link). This approach means many different GET vars could be used simultaneously to produce a filtered view, and that view could be "sticky" over different months.

an example url:

Code:
www.mydomain.com/forecast.php?mo=12&yr=2007&office=chicago&dept=sales&salesperson=bill

Under CI I could pass various URI segments to the controller function to replicate the functionality...but it appears to me they would always need to be in the same order for you to be able to map them to the correct "filter" option inside your controller function. They would not always appear in the same order, if for example you did not want to filter by office, only by dept. or by salesperson/dept, etc. Also, unlike a GET var it does not get passed as a name/value pair. I considered using URI segments such as "/dept.sales/office.chicago/" and splitting those variables inside the function to get the correct mapping, so the order in which they were passed to the function wouldn't matter. But there could be up to 7+ filters - it starts to get a bit clunky.

I suppose there is an option to use sessions to capture what "filters" are active, but with that approach you must "build" a filter to view it, and one would be unable to send someone a link that captured that entire view in the URI.

I certainly am not an expert and could easily be missing something obvious here about CI. Apologies for a long post and thanks for any thoughts you might have on how this could best be structured!

Doug
#2

[eluser]xwero[/eluser]
You can use key/value pairs like a query string and you can mimic the get global with the uri->segment_to_assoc
#3

[eluser]Unknown[/eluser]
Thanks for pointing that out. I knew there would be something I was missing.
#4

[eluser]Lone[/eluser]
Just as a quick example of using segment_to_assoc for your stated URL:

Code:
www.mydomain.com/sales/forecast/mo/12/yr/2007/office/chicago/dept/sales/salesperson/bill
#5

[eluser]codex[/eluser]
I think that would be 'uri->uri_to_assoc' instead of 'uri->segment_to_assoc'.

But very useful info guys. I didn't know of this function.
#6

[eluser]xwero[/eluser]
sorry of the misnamed method, but i did get two thirds of the name right :coolsmile:
#7

[eluser]Chris Newton[/eluser]
I use this:
http://codeigniter.com/wiki/URI_helper

to mimic the get string. I don't like using segment numbers. I prefer to use named variable/value pairs instead. The URI_helper makes it a little simpler (for me)




Theme © iAndrew 2016 - Forum software by © MyBB