Search code examples
phpsymfonyutf-8symfony-routing

Symfony: how to configure default options for all routes?


Can I configure the following option in a single place rather than per route?

In my routing.yml file every route has:

options:
    utf8: true

Because of

In Symfony 3.2, there is no need to explicitly set the utf8 option. As soon as Symfony finds a UTF-8 character in the route path or requirements, it will automatically turn on the UTF-8 support. However, this behavior is deprecated and setting the option will be required in Symfony 4.0.


Solution

  • Using Annotations it's possible in routing.yml to configure default options for all routes defined in AppBundle/Controller/ like this:

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

    Using Yaml you could try putting this directive at the very first place in 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.