gpt4 book ai didi

php - Yii2 渲染带有查询参数的 url

转载 作者:可可西里 更新时间:2023-10-31 22:54:16 25 4
gpt4 key购买 nike

我需要在 Yii2 Controller 操作中使用 render 向 url 添加一些参数。例如,将 cat=all 参数添加到以下网址:

localhost/sell/frontend/web/index.php?r=product/index

这是我的索引操作:

return $this->render('index', [
'product' => $product,
]);

最佳答案

您可以创建如下 URL:

yii\helpers\Url::toRoute(['product/index', 'cat' => 'all']);

你可以像下面这样在 Controller 中重定向:

$this->redirect(yii\helpers\Url::toRoute(['product/index', 'cat' => 'all']));

然后渲染你的 View 。

关于php - Yii2 渲染带有查询参数的 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27236233/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com