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
Every request sent to a symfony application is first analyzed by the routing system (which is simple because every request is handled by a single front controller). The routing system looks for a match between the request URL and the patterns defined in the routing rules.
The application can format a URL to bring information to the user, and the user can use the URL to access resources of the application. This is possible in symfony applications, because the URL presented to the end user is unrelated to the server instruction needed to perform the request.
To make things easy, symfony uses a syntax for internal URIs very similar to the one of regular URLs. Listing 9-1 shows an example. // Internal URI syntax <module>/<action> [?param1=value1] [¶m2=value2] [¶m3=value3]...
For instance, the URL /foo/123 matches both of the rules defined in Listing 9-16, but symfony first tests my_rule:, and as that rule matches, it doesn't even test the default: one. The request is handled by the mymodule/myaction action with bar set to 123 (and not by the foo/123 action).
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: .+
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With