"Posts", "action" =-6ren">
gpt4 book ai didi

cakephp - 如何从cakephp 3中的url访问参数

转载 作者:行者123 更新时间:2023-12-05 08:42:47 24 4
gpt4 key购买 nike

在cakephp 3的cook book中给出了构建url使用

echo $this->Url->build([
"controller" => "Posts",
"action" => "view",
"foo" => "bar"
]);

输出为

/posts/view/foo:bar

如何在操作中访问 foo:bar 并将其保存在变量 $foo 中?

最佳答案

食谱有误,所以我打开了this门票

如果您使用此代码

echo $this->Url->build([
"controller" => "Posts",
"action" => "view",
"foo" => "bar"
]);

你会得到这样的 url

/posts/view/?foo=bar

手册here解释如何访问 GET 参数

你可以做到

$this->request->query('foo');

 $this->request->query['foo'];

第一个是 null 安全的,这意味着如果未设置 'foo' 参数,您只会得到 null 而不是错误

编辑

3.4.0之后的新语法是

$this->request->getQuery('foo');

关于cakephp - 如何从cakephp 3中的url访问参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38760117/

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