On a multilingual website using Symfony, I've got a page with a login form embedded in the sidebar. Let's say I'm on the spanish version, the current url is mysite.com/es
. On this page, $request->getLocale()
gives me 'es'
, everything is fine.
However, if I submit the login form on this page, I get to mysite.com
. The 'es'
part in the url has disappeared and $request->getLocale()
gives me 'en'
. How can I make it so that my url and my locale don't change?
My form:
<form id="login-form" method="POST" action="/login-check">
<input type="text" id="userEmail" name="_username">
<input type="password" id="userPassword" name="_password">
<input type="hidden" name="_csrf_token" value="{{ fos_csrf_provider.generateCsrfToken('authenticate') }}">
</form>
My firewall:
main:
pattern: ^/
form_login:
provider: fos_userbundle
csrf_provider: form.csrf_provider
login_path: /
check_path: /login_check
logout:
path: my_site_logout
target: /
success_handler: my_site.logout_success_handler
anonymous: true
remember_me:
key: %secret%
You are looking for the following: http://symfony.com/doc/current/cookbook/session/locale_sticky_session.html
Sticky locale. I used this in one of my projects.