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

在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');

https://stackoverflow.com/questions/38760117/

相关文章:

django - 不可散列类型 : 'list' error when trying to add

java - 将 List> 转换为 int[][]

string - 如何在 go 模板中连接两个字符串?

scala - 为什么 For Comprehension 生成器会抑制 Option 类型?

php - 使用 cronjob 运行 php 文件中的函数

php - 如何过滤此 PHP 数组对象中的唯一对象

php - 上传文件在php中不起作用

oracle - 更新分区键,不允许行移动

c# - 如何在装饰器中定义事件和属性

r - R中二维核密度估计的混淆