views:

191

answers:

2

In symfony project, I would like to use an underscore as a separator for the parameter in routing.yml.

Url example: /article/lorem-1111_45.html

In routing.yml

rule_sample:
 url:      /article/:info-:datePublished_:id.html
 param:    { module: cms, action: test }
 options:
   segment_separators: ['-', '/', '.', '_']
 requirements:
   info: ^([A-Za-z0-9\-]+)$
   datePublished: \d+
   id: \d+

This code doesnt work. I have the following error: Unable to parse "/article/:info-:datePublished_:id.html" route near ":id.html".

Anybody knows how to implement this rule ?

A: 

I believe this is a bug in symfony.

I have made a test which failed and submitted a bug report with the test to the symfony project

johnwards
+1  A: 

I think is a bug in sfRoute.class.php. The line 683: 'variable_regex' => '[\w\d_]+'

in PHP \w "Matches any alpha numeric character including underscore (_)" and the last underscore matches the same. I've tried to change this line for: 'variable_regex' => '[\A-Za-z\d]+'

And now I can use underscore as a separator.

I haven't tested this very much. I don't know if this crashes any other features (surely), but maybe this is the line where the Symfony programmers can start this bug.

Alex