在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/