我遇到的问题是,当用户在登录页面中更改语言时 - 它可以工作,但在用户登录后 - 它再次恢复默认值。如何使登录前保持选择的相同语言用户成为可能,登录后保持不变?我试过在stackoverflow上查找这个,但找不到任何工作结果。
安全性.yml:
security:
encoders:
AppBundle\Entity\User:
algorithm: bcrypt
role_hierarchy:
ROLE_ADMIN: ROLE_PREMIUM
ROLE_PREMIUM: ROLE_USER
providers:
our_db_provider:
entity:
class: AppBundle:User
property: email
in_memory:
memory: ~
firewalls:
# disables authentication for assets and the profiler, adapt it according to your needs
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
main:
anonymous: ~
form_login:
#galima nurodyti kur nukreipia loginas
login_path: login
check_path: login
csrf_token_generator: security.csrf.token_manager
logout:
path: /logout
pattern: ^/
http_basic: ~
provider: our_db_provider
access_denied_url: homepage
路由.yml
app:
resource: "@AppBundle/Controller/"
type: annotation
prefix: /{_locale}
requirements:
_locale: lt|en|ru
root:
path: /
defaults:
_controller: FrameworkBundle:Redirect:urlRedirect
path: /%locale%/
permanent: true
login:
path: /{_locale}/login
defaults: { _controller: AppBundle:Security:login }
requirements:
_method: GET
_locale: lt|en|ru
logout:
path: /logout
defaults:
_controller: FrameworkBundle:Redirect:urlRedirect
path: /{_locale}/login
permanent: true
register:
path: /{_locale}/register
defaults: { _controller: AppBundle:Registration:register }
requirements:
_method: GET
_locale: lt|en|ru
语言更改为:
<ul class="top-menu-list top-menu-languages">
<li><a href="{{ path(app.request.attributes.get('_route'), app.request.query.all|merge({'_locale': 'lt'})) }}">LT</a></li>
<li><a href="{{ path(app.request.attributes.get('_route'), app.request.query.all|merge({'_locale': 'en'})) }}">EN</a></li>
<li><a href="{{ path(app.request.attributes.get('_route'), app.request.query.all|merge({'_locale': 'ru'})) }}">RU</a></li>
</ul>
任何想法或例子将不胜感激!