【发布时间】:2020-07-22 14:50:38
【问题描述】:
我需要重新生成我的页面的 URL,删除额外的参数。例如:当我收到:
/bao1/bao2/?removeMe1=anything&keepMe1=anything&removeMe2=&keepMe2=anything
我想生成删除了 removeMe 查询变量的 URL,但其他所有内容都完好无损。像这样:
/bao1/bao2/?keepMe1=anything&keepMe2=anything
我自动连接了请求:
public function __construct(RequestStack $httpRequest)
{
$this->httpRequest = $httpRequest;
}
那我就这样玩了:
public function getCleanUrl()
{
// HttpFoundation\Request
$currentHttpRequest = $this->httpRequest->getCurrentRequest();
// Trying to remove the parameters
$currentHttpRequest->query->remove("removeMe1");
return $currentHttpRequest->getUri()
}
query->remove("removeMe1") 有效,但是当我调用 getUri() 时,我仍然得到完整的输入 url,就好像从未调用过 remove()。我想我可能想打电话给某种$currentHttpRequest->regenerate()->getUri(),但我找不到任何东西。
【问题讨论】:
-
嗨@yivi!感谢您加入,但我在 1.5 年前发布了这个问题。我会接受你的答案,因为它看起来很可靠,但我无法在 ATM 上测试它。
标签: php symfony symfony-http-foundation