2

In PHP, I would do this to get 'points' as an multidimensional array.

<input type"text" name="points[0][1]" />
<input type"text" name="points[0][2]" />
<input type"text" name="points[1][1]" />
<input type"text" name="points[2][2]" />

Or if I wanted to get 'point' as an associative array:

<input type"text" name="point[x_axis]" />
<input type"text" name="point[y_axis]" />

What is the Catalyst/Perl equivalent for such things? How can I get these through $c->req->params ??

nsbm
  • 5,842
  • 6
  • 30
  • 45
  • 3
    I can't wait to send `name="points[100000000]"` to a PHP script! or is there a check for that? – ikegami Aug 02 '11 at 19:04
  • 1
    @ikegami since all arrays in PHP are secretly (ordered) associative arrays, it's more harmless than it looks — you get an array with one pair in it. – hobbs Nov 21 '12 at 01:27

1 Answers1

6

This isn't provided out-of-the-box — Catalyst doesn't do any mapping on param names, and maps the values to either scalars if they appear once, or arrayrefs if they appear multiple times. However there's a request trait you can apply, Catalyst::TraitFor::Request::Params::Hashed that adds hashed_params, hashed_query_params, and hashed_body_params methods to $c->request that behave in pretty much the way you want.

hobbs
  • 223,387
  • 19
  • 210
  • 288