Maintain locale after Symfony2 login
On a multilingual website using Symfony, I have a page with a login form embedded in the sidebar. Let's say I'm on the Spanish version, the current url mysite.com/es
. This page $request->getLocale()
gives me 'es'
everything in order.
However, if I submit a login form to this page, I get to mysite.com
. The part 'es'
in the url has disappeared, but $request->getLocale()
it gives me 'en'
. How can I keep my URL and my locale from changing?
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%
source to share
You are looking for the following: http://symfony.com/doc/current/cookbook/session/locale_sticky_session.html
Important locale. I used this in one of my projects.
source to share