使用 Symfony 的重定向功能时锚定 URL [英] Anchor in URL when using Symfony's redirect function

查看:23
本文介绍了使用 Symfony 的重定向功能时锚定 URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用

$this->redirect('route', array('id' => $id));

但我需要能够在末尾放置#"锚点,但我找不到这样做的方法.有什么想法吗?

but I need to be able to put "#" anchor at the end but I can't find a way of doing that. Any ideas?

代码

$this->redirect('route', array('id' => $id));

返回/route/id/5 但我希望能够创建/route/id/5#anchor7

returns /route/id/5 but I want to be able to create /route/id/5#anchor7

推荐答案

$this->redirect($this->generateUrl('route', array('id' => $id)) . '#anchor7');

<小时>

更新:

在 Symfony 3.2 中你可以这样做:

In Symfony 3.2 you can do this:

// 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

这篇关于使用 Symfony 的重定向功能时锚定 URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆