开发者

In Symfony2 how do I redirect within a Controller to a URL with an anchor tag/hash

开发者 https://www.devze.com 2023-04-11 23:31 出处:网络
I\'m in a Controller and I want to开发者_开发百科 redirect back to a URL, say /home/news/example#comment1423

I'm in a Controller and I want to开发者_开发百科 redirect back to a URL, say /home/news/example#comment1423

How can I add the hash in to the return params?

return $this->redirect(
    $this->generateUrl("news_view", array("permalink" => "example"))
);


The simplest solution would probably be concatenation:

$url = $this->generateUrl("news_view", array("permalink" => "example"));
return $this->redirect(
    sprintf('%s#%s', $url, 'comment1423')
);


In Symfony 3.2 you can do this:

// generating a URL with a fragment (/settings#password)
$this->redirectToRoute('user_settings', ['_fragment' => 'password']);

See https://symfony.com/blog/new-in-symfony-3-2-routing-improvements

0

精彩评论

暂无评论...
验证码 换一张
取 消