【问题标题】:Pass parameter through URL in Perl catalyst在 Perl 催化剂中通过 URL 传递参数
【发布时间】:2014-06-05 18:30:05
【问题描述】:

perl催化剂中是否可以通过URL传递参数 我有链接

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

我可以通过链接传递一个参数吗,比如

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

如果是这样,我如何获取模块中的值?

【问题讨论】:

    标签: perl catalyst


    【解决方案1】:

    我自己刚刚开始学习 Catalyst,但我可以说这似乎是 :Args 的用途。您指定所需的参数数量,并将它们添加到@_。我做了这个测试:

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

    并加载http://localhost:3000/test/hello。这会在浏览器和服务器输出中显示“hello”:

    [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 |
    '------------------------------------------------------------+-----------'
    

    这记录在Catalyst::Manual::Intro Action types.

    一系列控制器方法也可以检查同一个请求,每个方法都采用一定数量的“URL 参数”,:CaptureArgsaction chains.

    【讨论】:

    • $c->{'request'}{'arguments'};如果您有未定义或可变数量的参数,也会很有用。
    猜你喜欢
    • 1970-01-01
    • 2014-07-23
    • 2012-08-09
    • 1970-01-01
    • 1970-01-01
    • 2013-05-20
    • 1970-01-01
    • 1970-01-01
    • 2016-09-08
    相关资源
    最近更新 更多