I want to replace the emailtemplates router to contactpoints from the following URL


My routing pattern is: /config/workflow/configset-{configSetId}/partner_site/{steps}

I am currently using following code to generate a URL. But in this way I have to redefine the confgSetId, so, is there any other way to replace only "steps" (emailtemplates with contactpoints) route pattern?

        $routes = new RouteCollection();
        $routes->add('deploy_config', new Route('/config/workflow/configset-{configSetId}/partner_site/{steps}'));
        $context = new RequestContext();
        $urlGenerator = new UrlGenerator($routes, $context);
        $r = $urlGenerator->generate('deploy_config', array('configSetId' => $this->getConfigSet()->getId(), 'steps' => 'contactpoints'));

If I ask it simply I want to know: How to edit current URL inside a controller in Symfony2?


You could redirect to the new url like this assuming you are inside an action:

return $this->redirect($r);

Here is the relating part in the documentation:

To get the current route use this:

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

Therefore you need to implement the Request in the action:

use Symfony\Component\HttpFoundation\Request;
function someAction(Request $request){
dousi6405 我想将当前URL编辑为其他内容并在树枝模板中打印
接近 7 年之前 回复