在Symfony2中,如何在Controller内重定向到带有锚标记/哈希的URL [英] In Symfony2 how do I redirect within a Controller to a URL with an anchor tag/hash
本文介绍了在Symfony2中,如何在Controller内重定向到带有锚标记/哈希的URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在Controller中,我想重定向回URL,例如/ home / news / example#comment1423
I'm in a Controller and I want to redirect back to a URL, say /home/news/example#comment1423
如何在其中添加哈希
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')
);
这篇关于在Symfony2中,如何在Controller内重定向到带有锚标记/哈希的URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文