craft.request.getQuery() returns:

array (size=5)
  'tags' => string 'anxiety' (length=7)
  'maxPrice' => string '' (length=0)
  'sessions' => 
    array (size=4)
      0 => string 'email' (length=5)
      1 => string 'chat' (length=4)
      2 => string 'skype' (length=5)
      3 => string 'phone' (length=5)
  'hours' => 
    array (size=3)
      0 => string 'office' (length=6)
      1 => string 'evenings' (length=8)
      2 => string 'weekends' (length=8)

Whereas craft.request.getParam() throws an error:

PHP warning

Missing argument 1 for Craft\HttpRequestVariable::getParam(), called in /home/vagrant/Sites/counselling-anywhere/craft/app/vendor/twig/twig/lib/Twig/Template.php on line 609 and defined

This should have changed in Build #2465 right? I'm assuming it'll still work the same, but it's confusing that they don't return the same results.

Is this by design?


The behaviour you're seeing is by design – craft.request.getQuery() will return all GET variables if it's called without arguments, whereas craft.request.getParam() requires the name argument – i.e. craft.request.getParam('foo').

The changelog notes for build 1.3.2465 does reference a couple of issues related to these methods, but nothing suggesting any changes in regards to the required name argument for getParam(). Unfortunately, the GitHub repo for Craft builds doesn't go back as far as 1.3.2465, so I'm unable to verify this though.

  • 2
    The note in the changelog doesn't mean that all the params are being returned as one array (if not filtered down using the name argument), but that a single param can be an array. I'm no native english speaker, but I think you can read the note in both ways.
    – carlcs
    Feb 19 '16 at 12:44
  • Thanks for clearing that up guys. So I'm right in thinking request = craft.request.getParam() would require an if request.query before it returns any array (as @carlcs mentions, a single parameter array). Is this correct? I've asked this because there are a couple of the Stack Exchange examples, so assumed they were interchangeable. Are either preferable? The dot notation feels a bit cleaner to me.
    – Rob
    Feb 19 '16 at 18:39
  • No, you can't get an array back from getParam. Use getQuery or you have to get each one separatly with getParam(name), @Rob.
    – carlcs
    Feb 19 '16 at 18:46
  • I swear I thought I'd seen an example on here using just that, but it was yours @carlcs which does, in fact, use getQuery(). I think for many parameters it's a more succinct way of doing things. That release note was confusing me ;)
    – Rob
    Feb 19 '16 at 21:12
  • 1
    Yes, it has potential to confuse. I also wasn't sure if I might have posted here on SE, making use of craft.request.getParam in a wrong way. I searched for it, but didn't found anything. Puuuhh! :)
    – carlcs
    Feb 19 '16 at 21:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.