在 cakephp 3 的烹饪书中。给出了使用构建 url
echo $this->Url->build([
"controller" => "Posts",
"action" => "view",
"foo" => "bar"
]);
这将输出为
/posts/view/foo:bar
如何访问实际foo:bar
操作并保存在变量中$foo
?
在 cakephp 3 的烹饪书中。给出了使用构建 url
echo $this->Url->build([
"controller" => "Posts",
"action" => "view",
"foo" => "bar"
]);
这将输出为
/posts/view/foo:bar
如何访问实际foo:bar
操作并保存在变量中$foo
?
食谱中有错误,所以我打开了这张票
如果您使用此代码
echo $this->Url->build([
"controller" => "Posts",
"action" => "view",
"foo" => "bar"
]);
你会得到一个这样的网址
/posts/view/?foo=bar
此处的手册解释了如何访问 GET 参数
你可以做
$this->request->query('foo');
或者
$this->request->query['foo'];
第一个是空安全的,这意味着如果foo
未设置“”参数,您只需获取null
而不是错误
编辑
3.4.0 之后的新语法是
$this->request->getQuery('foo');
或者在一行中将所有参数作为数组获取:
$params = $this->request->getQueryParams();
CakePHP 3.* 版本可以使用 request Query :
$this->request->getQuery('utm_source')