Symfony2: How to: secure application with _locale Symfony2: How to: secure application with _locale php php

Symfony2: How to: secure application with _locale


Just make sure you define routes for them all that do use the locale variable and security seems to pick it up automatically. No need to have the locale accounted for in the security config.

Here's an example from my project.

Excerpt from security.yml:

    login:        pattern:  /(game|admin)/login$        security: false    admin:        pattern:    /admin/        form_login:            check_path: /admin/login_check            login_path: _admin_login        logout:            path:   _admin_logout            target: _home    game:        pattern:    /game/        form_login:            check_path: /game/login_check            login_path: _game_login        logout:            path:  _game_logout            target: _home

Excerpt from routing.yml:

BrowserMMOSecurityBundle:    resource: "@BrowserMMOSecurityBundle/Controller/"    type:     annotation    prefix:   /{_locale}/    defaults: { _locale: en }    requirements:        _locale: en|fr_game_login_check:    pattern:   /game/login_check_admin_login_check:    pattern:   /admin/login_check_admin_logout:    pattern:   /{_locale}/admin/logout    requirements:        _locale: en|fr_game_logout:    pattern:   /{_locale}/game/logout    requirements:        _locale: en|fr

The above config works for me. It's also worth noting that the _admin_login and _game_login routes are defined in annotations on my SecurityController class.