5
votes

I use Symfony 2.2.4, and I try desperately to generate URL (with Twig). In fact, I obtain always the same error when my URL cointain a dot.

For example : - Route: "my_route" - First parameter: "id" - Second parameter: "title"

In Twig:

{{ path("my_route", {"id" : 1984, "title" : "another...test"}) }}

I obtain the following error:

An exception has been thrown during the rendering of a template ("Parameter "title" for route "my_route" must match "[^/.]++" ("another...test" given) to generate a corresponding URL.") in ...

I've tried with Symfony 2.0.3, and there are no problem.

Have you got an idea to resolve this problem?

Thanks by advance for your help.

Best regards

2
Use backslash instead of forward slash to match a dot. Right not the requirement is Match non-forward-slash and non-character, actually can we see the route configuration.Flosculus
More precisely, error occurs when I add suffix on my route. For example: "pattern: /show/{id}/{title}.html"JohnDoe66
Need to see the route configuration (yml, xml, annotations), the controller action method (and the class annotations if any), and the url you are using.Flosculus
I had a similar issue that was a problem because my router was not forwarding calls to files that weren't php... in my case that was BrowserSync.Ray Foss

2 Answers

7
votes

If you use a suffix, you should add it in the requirement of the route and use {_format} instead of "html" :

Example from the documentation :

article_show:
  path:     /id/{title}.{_format}
  defaults: { _controller: AcmeDemoBundle:Article:show, _format: html }
  requirements:
      _format:  html
      title:     .+

EDIT :

You should avoid using dots (".") for your parameter. You should really use a slug of your title. But you could try in the requirements a regex to allow having dots in the title parameter.

  requirements:
      _format:  html
      title:     .+
0
votes

Old question, but since there still are old SF codebases out there, this may save up some time to someone.

This is an issue with how SF compiles the regex to match the routes. This applies at least to version 1.x and 2.x, not sure about newer versions.

In your routing.yml you need to specify the expected format of your title parameter under requirements, as shown below:

my_route:
  url: /my_route/:id/:title
  param: { module: your_module, action: your_action }
  requirements: {title: .+}

Alternatively, instead of using requirements, specifying the segment separator on your route also does the trick:

my_route:
  url: /my_route/:id/:title
  param: { module: your_module, action: your_action }
  options: { segment_separators: [/] }