0

I'm trying to create a special route that handles confirmation of a certain action. For instance, if I'm trying to access a route /admin/user/1/delete, I want to go to a different route first to show a special html page that confirms they want to complete an action (ie. confirm/admin/user/1/delete) and on the page there's a confirm button that goes to the route and a go back button that redirects to the referrer.

In the example below, is there a way to allow {route} to be anything and pass that into a twig page?

/**
* @Route("/confirm/{route}", name="confirm_dialog")
* @param type $route
*/
public function confirmAction($route)
{
}
showdev
  • 28,454
  • 37
  • 55
  • 73
David W
  • 1,833
  • 5
  • 21
  • 25
  • Why not just pass your confirmation route in the querystring E.g. /confirm?route=/admin/user/1/delete - seems simpler – Richard Jun 09 '15 at 19:38

1 Answers1

0

There is a cookbook covering this specific use case: http://symfony.com/doc/current/cookbook/routing/slash_in_parameter.html

By default, the Symfony Routing component requires that the parameters match the following regex path: "[^/]+". This means that all characters are allowed except "/".
You must explicitly allow "/" to be part of your parameter by specifying a more permissive regex path: ".+"

/**
* @Route("/confirm/{route}", name="confirm_dialog", requirements={"route"=".+"})
* @param type $route
*/
public function confirmAction($route)
{
    // ...
}

But I would not recommend the pattern you are trying to use. I would recommend to have the same route "/admin/user/1/delete" using GET to display a confirmation form and using POST to perform the deletion. If you don't want to repeat the code for asking confirmation, you can always extract that specific code.

Geoffroy
  • 146
  • 5
  • Thanks Geoffroy, That's what I was looking for, just didn't know what to call it. I was thinking about doing it the way you mentioned, but then I would need to have two methods for each route which could be in the 100+ range. – David W Jun 10 '15 at 14:06
  • you don't need to have different methods, just check if it's a POST in the action – Geoffroy Jun 10 '15 at 14:29