gpt4 book ai didi

perl - Catalyst:将查询参数传递给 "forward"调用

转载 作者:行者123 更新时间:2023-12-04 10:59:17 24 4
gpt4 key购买 nike

我有一个 Catalyst Controller ,它以通常的方式响应参数 ( /endpoint/foo/bar ),但也接受安全 token 的查询参数。如何在启动 forward 之前设置参数的值调用此 Controller ?它不允许我分配给 $c->req->param('token') .

(不可能重写 Controller 以接受 token 作为参数而不是参数。)

最佳答案

$c->req->param('token')不是 LValue,所以你不能分配给它。相反,您需要 to pass in the value .

$c->req->param('token', 1);

这种行为被记录在案:

Like CGI, and unlike earlier versions of Catalyst, passing multiple arguments to this method, like this:

 $c->request->param( 'foo', 'bar', 'gorch', 'quxx' );

will set the parameter foo to the multiple values bar, gorch and quxx. Previously this would have added bar as another value to foo (creating it if it didn't exist before), and quxx as another value for gorch.



考虑这个演示:

package MyApp::Controller::Root;
use base 'Catalyst::Controller';
__PACKAGE__->config(namespace => '');

sub default : Path {
my ($self, $c) = @_;
$c->req->param('foo', 1);
$c->forward('bar');
}

sub bar : Path('foo') {
my ($self, $c) = @_;

if ($c->req->param('foo')) {
$c->res->body("Secret param set!\n");
}
else {
$c->res->body("Hello World\n");
}
return;
}

关于perl - Catalyst:将查询参数传递给 "forward"调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58935999/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com