4

Is it possible to pass a parameter through URL in perl catalyst I have a link

<a href="/vbo/mortgage_reduction/yearly" >Yearly </a>

Can I pass a parameter with the link, like

<a href="/vbo/mortgage_reduction/yearly/1" >Yearly</a>

if so, how can I take the value in the module ?

Jitesh
  • 345
  • 1
  • 5
  • 16

1 Answers1

4

I have just started learning Catalyst myself, but I can say that seems to be what :Args is for. You specify the number of parameters you need and they are added to @_. I have made this test:

sub test :Local :Args(1) {
    my ( $self, $c, $word ) = @_;
    $c->response->body($word);
}

and loaded http://localhost:3000/test/hello. This displayed "hello" in the browser and the server output:

[info] *** Request 1 (0.083/s) [14444] [Thu Jun  5 11:29:18 2014] ***
[debug] Path is "test"
[debug] Arguments are "hello"
[debug] "GET" request for "test/hello" from "127.0.0.1"
[debug] Response Code: 200; Content-Type: text/html; charset=utf-8; Content-Length: unknown
[info] Request took 0.00722s (138.504/s)
.------------------------------------------------------------+-----------.
| Action                                                     | Time      |
+------------------------------------------------------------+-----------+
| /test                                                      | 0.000194s |
| /end                                                       | 0.000265s |
'------------------------------------------------------------+-----------'

This is documented in Catalyst::Manual::Intro under Action types.

It is also possible for a series of controller methods to examine the same request, each taking a certain number of those "URL parameters", with :CaptureArgs and action chains.

scozy
  • 2,511
  • 17
  • 34
  • $c->{'request'}{'arguments'}; would also be useful if you have an undefined or variable number of arguments. – bart_88 Sep 25 '14 at 00:37