开发者

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 t开发者_开发问答he problem of "route not matching".

So how to pass an url as an argument ?


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' }) }}


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜