symfony - 在 Symfony2 中,如何在 Controller 内重定向到带有 anchor 标记/哈希的 URL

标签 symfony routes

我在 Controller 中,我想重定向回某个 URL,例如/home/news/example#comment1423

如何将哈希值添加到返回参数中?

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

最佳答案

最简单的解决方案可能是串联:

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

关于symfony - 在 Symfony2 中,如何在 Controller 内重定向到带有 anchor 标记/哈希的 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7724082/

相关文章:

php - 从 Sonata-admin 的侧边菜单中删除子管理员

控制台命令上的Symfony Profiler

c# - RouteData.Values 保持为空

routes - BottomNavigationBar保存偏移位置并导航到细节 flutter

javascript - Express - 将 JavaScript 数据传递给客户端,无需 View 引擎

asp.net-mvc - 使用自定义路由代替/controller/action/{id}

php - Symfony2 使用 json 进行 ajax 请求

symfony - FOSUserBundle 和 ACL 业务角色

php - 当我已经在模拟另一个用户时模拟另一个用户?

javascript - slim 的路线给了我 404