开发者

Multidimensional and associative array (hash) via POST in Perl/Catalyst

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 ??


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜