Pass parameter via url in Perl catalyst

Is it possible to pass parameter via url in perl catalyst I have a link

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

Can I pass a parameter with a link, for example

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

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

+4
source share
1 answer

I was just starting to learn Catalyst myself, but I can say that for him, apparently, for :Args. You specify the number of required parameters, and they are added to @_. I did this test:

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

and loaded http://localhost:3000/test/hello. This displayed a hello in the browser and on 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 described in Catalyst::Manual::Introthe section Types of actions.

, , " URL", :CaptureArgs .

+3

Source: https://habr.com/ru/post/1543334/


All Articles