【问题标题】:Symfony: how to configure default options for all routes?Symfony:如何为所有路由配置默认选项?
【发布时间】:2017-10-23 07:05:00
【问题描述】:

我可以在一个地方而不是每条路线上配置以下选项吗?

在我的routing.yml 文件中,每条路线都有:

options:
    utf8: true

因为

在 Symfony 3.2 中,不需要显式设置 utf8 选项。一旦 Symfony 在路由路径或需求中发现 UTF-8 字符,它就会自动开启 UTF-8 支持。但是,这种行为已被弃用,在 Symfony 4.0 中需要设置该选项。

【问题讨论】:

    标签: php symfony utf-8 symfony-routing


    【解决方案1】:

    使用注解,可以在routing.yml 中为AppBundle/Controller/ 中定义的所有路由配置默认选项,如下所示:

    app_bundle:
        resource: "@AppBundle/Controller/"
        type:     annotation
        schemes:  "https"
        options: { utf8: true }
    

    使用 Yaml 您可以尝试将此指令放在 routing.yml 的最前面:

    app_name:
        path: ^/
        #path: ^/* <-- another attempt to include all routes after the first /
        options: { utf8: true }
        #host: <-- maybe you should specify this and/or other params depending by your needs.
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-03
      • 1970-01-01
      • 2012-03-17
      相关资源
      最近更新 更多