Symfony2 error when URL contains period (.)

I am using Symfony 2.2.4 and I am desperate to create a URL (with Twig). In fact, I always get the same error when my URL concatenates the dot.

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

In Twig:

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

I get the following error:

An exception was thrown during the rendering of the template ("The title parameter for the route my_route must match [^ /.] ++" ("another ... test") to create the corresponding URL. ") In .. .

I tried with Symfony 2.0.3 and no problem.

Do you have an idea to solve this problem?

Thanks for the help for the help.

Regards

+4
source share
1 answer

If you use a suffix, you must add it to the route requirement 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 periods (".") For your parameter. You really have to use the slug of your name. But you can try regex as required to allow dots in the title parameter.

  requirements: _format: html title: .+ 
+6
source

Source: https://habr.com/ru/post/1495695/


All Articles