【问题标题】:Symfony 1.4 require a domain name in routingSymfony 1.4 在路由中需要域名
【发布时间】:2012-10-16 10:52:56
【问题描述】:

我需要在我的 symfony 路由中要求一个域名,我的路由如下所示:

domain_example:
url: /routing/example/:domain_name
param: { module: myModule, action: index, sf_format: json }
requirements: { domain_name: '/^[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}$/' }

我也试过了:

requirements: { domain_name: '[/^[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}$/]' }

如果我这样称呼我的路线:mydomain.com/routing/example/otherdomain.com - 我只是得到模块/动作不存在异常。

【问题讨论】:

标签: php symfony1 url-routing


【解决方案1】:

总结一下

点在 Symfony 中使用 as segment separator。所以你应该在你的路由中添加这个选项来强制 Symfony 只使用/ 作为分隔符:

  options:
    segment_separators: [/]

接下来,你的正则表达式是错误的,但是 SO has one for you:

[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?

您的最终路线:

domain_example:
  url: /routing/example/:domain_name
  param:
    module: main
    action: index
    sf_format: json
  requirements:
    domain_name: '[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?'
  options:
    segment_separators: [/]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-04-18
    • 2011-06-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多