我在控制器中,我想重定向回URL,比如/ home / news / example#comment1423
如何将哈希值添加到返回参数中?
return $this->redirect(
$this->generateUrl("news_view", array("permalink" => "example"))
);
答案 0 :(得分:28)
最简单的解决方案可能是连接:
$url = $this->generateUrl("news_view", array("permalink" => "example"));
return $this->redirect(
sprintf('%s#%s', $url, 'comment1423')
);
答案 1 :(得分:4)
在Symfony 3.2中,您可以这样做:
// generating a URL with a fragment (/settings#password)
$this->redirectToRoute('user_settings', ['_fragment' => 'password']);
请参阅https://symfony.com/blog/new-in-symfony-3-2-routing-improvements