These forums are read-only and for archival purposes only!
Please join our new forums at discourse.kohanaframework.org
REST request parameters
  • I need to make some REST requests which may include the same parameter name more than once. (For example: ....&bucket=this&bucket=that.... ).

    Kohana's Request class doesn't allow this, as its _get property is an array so each param name can exist only once.

    Has anyone else encountered this, and if so how to work around it?

  • Rename it. $_GET/$this->request->query() shouldn't support it either.

  • Have you tried &bucket[]=this&bucket[]=that

    -> e.g. $_GET:

    Array
    (
        [bucket] => Array
            (
                [0] => this
                [1] => that
            )
    
    )
    
  • HTTP doesn't allow this. Has nothing to do directly with kohana.

  • Well, bucket=this&bucket=that will still appear as is in $_SERVER['QUERY_STRING'], if not in $_GET, so it can still be used if you want to hack it. But the example I gave is the most common.

  • ?bucket=this,that
    

    ... then explode it...

    • H
  • Thanks guys.

    @zombor: what is your evidence that "HTTP doesn't allow this"? The request works perfectly well if keyed in to the address bar, and the API in question is well-used within its sphere of interest.

    @zeebee: I tried array indexes, but my low expectations were fulfilled :-) But as you (and Henrik) say, I could hack it and it looks like I'll have to.

  • I haven't seen any web server/whatever does parsing "support" this. They always clobber the keys into the last one. "Supporting" it makes no sense, what would happen? You have duplicate keys, they must be clobbered, just like duplicate array or hash keys.

  • Since in this case it's a matter for PHP rather than HTTP, which doesn't care about query strings, what we can say for certain is: in converting a query string to $_GET, PHP chooses to clobber duplicate keys rather than convert to array. Instead, it chooses to support only the array syntax for duplicate keys, no doubt with good reason ... whatever it may be.

    According to this discussion, there's little consistency across frameworks, since there isn't a standard. Some clobber, some don't:

    http://stackoverflow.com/questions/1746507/authoritative-position-of-duplicate-http-get-query-keys

  • Fair enough. Every system that i've worked in has clobbered them (not just php). I figured it was the server that did it.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion