Symfony2通过从当前URL替换路由器模式变量来创建URL(如何编辑当前URL?)

时间:2013-12-19 11:49:41

标签: php symfony routing symfony-2.3

我想将emailtemplates路由器替换为以下网址中的contactpoints

  http://localhost/app_dev.php/config/workflow/configset-72/partner_site/emailtemplates

我的路由模式是: / config / workflow / configset- {configSetId} / partner_site / {steps}

我目前正在使用以下代码生成网址。但是通过这种方式,我必须重新定义confgSetId,因此,还有其他任何方式只能替换steps”(emailtemplates与{{1}路线模式?

contactpoints

如果我问它只是想知道: 如何编辑Symfony2中控制器内的当前URL?

1 个答案:

答案 0 :(得分:1)

您可以重定向到这样的新网址,假设您在某个操作中:

return $this->redirect($r);

以下是文档中的相关部分:http://symfony.com/doc/current/book/controller.html#redirecting

要获取当前路线,请使用此选项:

$currentRoute = $request->attributes->get('_route');
$currentUrl = $this->get('router')->generate($currentRoute, array(), true);

因此,您需要在操作中实现请求:

use Symfony\Component\HttpFoundation\Request;
...
function someAction(Request $request){