且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Symfony2如何允许在路由正则表达式中使用破折号?

更新时间:2022-04-28 04:54:24

默认情况下禁止使用斜线.您可以通过更改默认要求来启用它们.在您的情况下,***对 id 提出要求,因为它用破折号分隔.

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.

请参阅下面的示例.

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