【发布时间】: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催化剂中是否可以通过URL传递参数 我有链接
<a href="/vbo/mortgage_reduction/yearly" >Yearly </a>
我可以通过链接传递一个参数吗,比如
<a href="/vbo/mortgage_reduction/yearly/1" >Yearly</a>
如果是这样,我如何获取模块中的值?
【问题讨论】:
我自己刚刚开始学习 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 参数”,:CaptureArgs 和 action chains.
【讨论】: