CakePHP 3 - 如何在将合并当前 URL 参数的视图中生成 link?
CakePHP 3 - How do I generate a link in a view which will combine the current URL param?
你好 CakePHP 朋友们。
请问您如何在视图中生成 link 的建议,
它具有 "?" => []
但不会清除用户正在浏览的 URL 中的原始参数?
例如,
<?= $this->Html->link("Blue", ["?" => ["color" => "blue"]]) ?>
生成一个 link 用于在 URL 中传递参数,例如 ?color=blue
比方说,用户点击了这个link,我想给他提供另一个link来添加1个或多个条件。
<?= $this->Html->link("Circle", ["?" => ["shape" => "circle"]]) ?>
生成一个 link 就像 ?shape=circle
.
但我希望是:?color=blue&shape=circle
。
请帮忙。谢谢你。有的话直接写在回答里就可以了
您只需要合并两个 ?
数组:-
<?= $this->Html->link("Blue Circle", ["?" => ["color" => "blue", "shape" => "circle"]]) ?>
您可以在
中找到您的查询参数
$this->request->query
所以你可以使用 array_merge
$query = array_merge($this->request->query, ["shape" => "circle"]);
echo $this->Html->link("Circle", $query)
你好 CakePHP 朋友们。
请问您如何在视图中生成 link 的建议,
它具有 "?" => []
但不会清除用户正在浏览的 URL 中的原始参数?
例如,
<?= $this->Html->link("Blue", ["?" => ["color" => "blue"]]) ?>
生成一个 link 用于在 URL 中传递参数,例如 ?color=blue
比方说,用户点击了这个link,我想给他提供另一个link来添加1个或多个条件。
<?= $this->Html->link("Circle", ["?" => ["shape" => "circle"]]) ?>
生成一个 link 就像 ?shape=circle
.
但我希望是:?color=blue&shape=circle
。
请帮忙。谢谢你。有的话直接写在回答里就可以了
您只需要合并两个 ?
数组:-
<?= $this->Html->link("Blue Circle", ["?" => ["color" => "blue", "shape" => "circle"]]) ?>
您可以在
中找到您的查询参数$this->request->query
所以你可以使用 array_merge
$query = array_merge($this->request->query, ["shape" => "circle"]);
echo $this->Html->link("Circle", $query)