3

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 ?

2 Answers 2

2

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' }) }}
Sign up to request clarification or add additional context in comments.

Comments

0

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

1 Comment

While the link here is helpful, it would be better to copy the relevant portions here, also. Not everyone can access external sites, and the links may break over time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.