Saperlipopette
Saperlipopette

Reputation: 424

Symfony 2 routing with an url as argument

I've got some troubles when trying to pass an Url as argument in Symfony2.

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

When i'm trying to go to : /web/app_dev.php/mark/1307374717828/http%3A%2F%2Flocalhost%2Fweb%2Fapp_dev.php%2Fhome%2F

I've got a not found page, it seems that it doesn't look to symfony because I haven't the problem of "route not matching".

So how to pass an url as an argument ?

Upvotes: 3

Views: 3010

Answers (2)

FaZ
FaZ

Reputation: 46

By default Symfony does not match the character "/"; You have to specifically allow it as described here in the Symfony documentation.

Upvotes: 0

tuxedo25
tuxedo25

Reputation: 4828

This isn't as elegant a use of routing as being able to say pattern: mark/{date}/{url}, but you could 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 link to /web/app_dev.php/mark/1307374717828?url=http%3A%2F%2Flocalhost%2Fweb%2Fapp_dev.php%2Fhome%2F

Or using twig:

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

Upvotes: 2

Related Questions