Symfony2 how to allow slug with dashes in routes regex?

后端 未结 3 607
旧时难觅i
旧时难觅i 2020-12-16 14:54

My route (slug contains dashes!):

region:
  pattern: /regione/{slug}-{id}
  defaults: { _controller: SWAItaliaInCifreBundle:Default:region }
<
3条回答
  •  有刺的猬
    2020-12-16 15:12

    Slashes are by default forbidden. You can enable them by changing the default requirements. In your case it'd be also good to give requirements for the id as it's separated with dash.

    See example below.

    region:
        pattern: /regione/{slug}-{id}
        defaults:
            _controller: SWAItaliaInCifreBundle:Default:region
        requirements:
            slug: "[a-zA-Z1-9\-_\/]+"
            id: "\d+"
    

提交回复
热议问题