1

大家好 CakePHP 朋友。

我是否可以建议我如何在视图中生成链接,该链接具有"?" => []但不会清除用户正在浏览的 URL 中的原始参数?

例如,

<?= $this->Html->link("Blue", ["?" => ["color" => "blue"]]) ?>

生成一个用于在 URL 中传递参数的链接,例如?color=blue

假设用户点击了这个链接,我想为他提供另一个链接来添加 1 个或多个条件。

<?= $this->Html->link("Circle", ["?" => ["shape" => "circle"]]) ?>

生成一个链接,如?shape=circle.

但我希望它会是:?color=blue&shape=circle

请帮忙。谢谢你。如果你有答案,你可以只写答案。

4

2 回答 2

2

你可以找到你的查询参数

$this->request->query

所以你可以使用array_merge

$query = array_merge($this->request->query, ["shape" => "circle"]);
echo $this->Html->link("Circle", $query) 
于 2015-12-16T10:53:21.643 回答
0

你只需要结合你的两个?数组: -

<?= $this->Html->link("Blue Circle", ["?" => ["color" => "blue", "shape" => "circle"]]) ?>
于 2015-12-16T10:32:46.577 回答