Symfony 2 routing with url as argument

I am having trouble trying to pass Url as an argument to Symfony2.

My routing.yml has this template: pattern: mark/{date}/{url}

When I try to go to: /web/app_dev.php/mark/1307374717828/http%3A%2F%2Flocalhost%2Fweb%2Fapp_dev.php%2Fhome%2F

I have a page not found, it looks like it is not looking at symfony because I have no problem with the "route not matching".

So how to pass a url as an argument?

+3
source share
2 answers

It's not as elegant as using routing, as you can say pattern: mark / {date} / {url}, but you can just look for the "url" part as a query parameter.

(in routing.yml)

_testurlthing:
    pattern: /mark/{date}
    defaults: { _controller: AcmeTestUrlBundle:Url:mark }

(in AcmeTestUrlBundle / Controllers / UrlController.php)

public function markAction($date)
{
  $url = $this->get('request')->get('url');
  return new Response("sending you to $url");
}

Now you can go to /web/app_dev.php/mark/1307374717828?url=http%3A%2F%2Flocalhost%2Fweb%2Fapp_dev.php%2Fhome%2F

Or using a twig:

{{ path('_testurlthing', { 'date': 1307374717828, 'url': 'http%3A%2F%2Flocalhost%2Fweb%2Fapp_dev.php%2Fhome%2F' }) }}
+2

Symfony "/"; , , Symfony.

0

All Articles