Passing null arguments in url |
[eluser]msteudel[/eluser]
So I have a search page that can accept three values keyword date_to date_from You only need to pass one into the search form. The search form needs to be able to accept both POST and GET values. (Either post from or form, or create a link that a user can click on and it shows search results) I originally though I would pass them thru the url search/index/search+term/12-10-2009/12-11-2009 BUT if I only want to pass the dates in and do search/index//12-10-2009/12-11-2009 The routing shifts them over, e.g. date_to becomes keyword. So I had a couple of thoughts on how to solve this: 1. for arguments that aren't being used, pass in null e.g. search/index/null/12-10-2009/12-11-2009 2. serialize and base64 encode an array e.g. search/index/dawef987a98fw7e987aawe9f8a7we9f8 3. Try and pass name value pairs e.g. search/index/keywords=mark+test&date=12-11-2009 4. Use sessions Anyway, I'm leaning towards option 1 but was wondering if anyone had any other thoughts on how to do this. Mark
[eluser]bretticus[/eluser]
Another reason a purely segment-based URL schema falls down in my humble opinion. You could just enable querystrings... Or you could use custom URI Routing to get rid of that ugly "null" segment. Another thing you can do is use func_get_args() to work with a variable amount of arguments that are not "place-held." I would just enable querystrings personally.
[eluser]msteudel[/eluser]
Yeah it' funny I was working on this, and was looking at the nulls, thinking, that kinda looks bad.... maybe I'll enable query strings just for that controller ...
[eluser]bretticus[/eluser]
[quote author="msteudel" date="1287115433"]... maybe I'll enable query strings just for that controller ...[/quote] Yeah, I know I stand up on my soapbox about this, but GET is GET damnit! I suggested, in my blog tutorial, Code: parse_str(substr(strrchr($_SERVER['REQUEST_URI'], "?"), 1), $_GET); But I've seen evidence that: Code: parse_str($_SERVER['QUERY_STRING'], $_GET); works with Code: $config['uri_protocol'] = "PATH_INFO"; Great way to enable for one controller. EDIT: I mentioned using func_get_args(). That might work, but using $this->uri->segment_array() is probably less error prone.
[eluser]tonanbarbarian[/eluser]
use $this->uri->uri_to_assoc(n) http://ellislab.com/codeigniter/user-gui...s/uri.html the the url would be in the following format search/index/keyword/search+term/date_to/12-10-2009/date_from/12-11-2009 This would then produce the following assoc array Code: $segments = $this-uri->uri_to_assoc(2); $segments['date_to'] would be '12-10-2009' $segments['date_from'] would be '12-11-2009' and if you dont want one section you can have the following url search/index/date_to/12-10-2009/date_from/12-11-2009 This would then produce the following assoc array Code: $segments = $this-uri->uri_to_assoc(2); $segments['date_from'] would be '12-11-2009' $segments['keyword'] would not be defined in this case |
Welcome Guest, Not a member yet? Register Sign In |