我依靠Winzou的教程("翻译其网站")来安装FOSuserBundle模块,正如我所料,我遇到了路由和前缀/{_locale}/
的问题,以使其运行,我将security.xml文件从FOSUserBundle复制到我的userBundle,我有/{_locale}/
的前缀路由,我将此文件导入我的app/config/routing.yml
。
当我在Firefox中转到app.php/en/login
时,它说Firefox已检测到服务器以永远无法完成的方式重定向此地址的请求。 Chrome中的结果是"此网页有一个重定向循环"错误代码为ERR_TOO_MANY_REDIRECTS。
当我禁用前缀并且我连接时没有/fr
,然后我重新激活了前缀,该网站适用于前缀,当我断开连接和/或我想重新连接时它不起作用... < / p>
有关router: debug
命令的信息
fos_user_security_login GET | POST ANY ANY / local {_} / login
这两天我尝试了在论坛中找到的所有解决方案,但都没有效果。与此同时,所有这些帖子都开始约会......提前感谢您的帮助,因为我被困在这里真诚地
如果我将prefixe / {_ locale} /添加到我的bundl的路由(routing.yml) 为了能够翻译我的页面(/ fr / mypage或/ en / mypage) routes / fr / login(或en / login /)和/ fr / logout(或/ en / logout)不是可访问的... 您可以在3个附加文件中查看我的配置(/app/config/routing.yml,/app/config/security.yml和userBundle / Resources / config / routing / security.xml
# /app/config/routing.yml
#OS_user:
# resource: "@OSUserBundle/Resources/config/routing.yml"
# prefix: /
OS_site:
resource: "@OSSiteBundle/Resources/config/routing.yml"
# prefix: /
prefix: /{_locale}/
app:
resource: "@AppBundle/Controller/"
type: annotation
# app/config/security.yml
fos_js_routing:
resource: "@FOSJsRoutingBundle/Resources/config/routing/routing.xml"
_liip_imagine:
resource: "@LiipImagineBundle/Resources/config/routing.xml"
#login:
# pattern: /login
# defaults: { _controller: OSUserBundle:Security:login }
#login_check:
# pattern: /login_check
#logout:
# pattern: /logout
fos_user_security:
resource: "@OSUserBundle/Resources/config/routing/security.xml"
# app\config\security.yml
# To get started with security, check out the documentation:
# http://symfony.com/doc/current/book/security.html
security:
# http://symfony.com/doc/current/book/security.html#where-do-users-come-from-user-providers
encoders:
#Symfony\Component\Security\Core\User\User: plaintext
#Symfony\Component\Security\Core\User\User: plaintext
OS\UserBundle\Entity\User: sha512
role_hierarchy:
ROLE_DESIGNER: ROLE_COMPANY ROLE_COMPANY_USER ROLE_WELLBEING ROLE_CULTURAL ROLE_INDIVIDUAL
ROLE_USER: ROLE_DESIGNER
ROLE_ADMIN: ROLE_USER
ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]
providers:
#in_memory:
# memory:
# users:
# user: { password: userpass, roles: [ 'ROLE_USER' ] }
# admin: { password: adminpass, roles: [ 'ROLE_ADMIN' ] }
main:
#entity:
# class: OS\UserBundle\Entity\User
# property: username
id: fos_user.user_provider.username
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
# On crée un pare-feu uniquement pour le formulaire
main_login:
# Cette expression régulière permet de prendre /login (mais pas /login_check !)
pattern: ^/login$
anonymous: true # On autorise alors les anonymes sur ce pare-feu
main:
pattern: ^/
anonymous: false
provider: main
form_login:
login_path: fos_user_security_login
check_path: fos_user_security_check
logout:
path: fos_user_security_logout
target: /
remember_me:
key: %secret%
access_control:
#- { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY, requires_channel: https }
#- { path: ^/admin, roles: ROLE_ADMIN }
#- { path: ^/admin, ip: 127.0.0.1, requires_channel: https }
userBundle /资源/配置/路由/ security.xml文件
<?xml version="1.0" encoding="UTF-8" ?>
<routes xmlns="http://symfony.com/schema/routing"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd">
<route id="fos_user_security_login" path="/{_locale}/login" methods="GET POST">
<default key="_controller">FOSUserBundle:Security:login</default>
</route>
<route id="fos_user_security_check" path="/login_check" methods="POST">
<default key="_controller">FOSUserBundle:Security:check</default>
</route>
<route id="fos_user_security_logout" path="/{_locale}/logout" methods="GET">
<default key="_controller">FOSUserBundle:Security:logout</default>
</route>
</routes>