Symfony2的新用户。
我正在尝试使用FOSUserBundle设置防火墙。
/ admin / 需要用户成为管理员后,我已经掌握了所有内容。
但是,我想将登录路径移至 / admin / login ,而不只是 / login
Security.yml
security:
encoders:
FOS\UserBundle\Model\UserInterface: sha512
role_hierarchy:
ROLE_ADMIN: ROLE_USER
ROLE_SUPER_ADMIN: ROLE_ADMIN
providers:
fos_userbundle:
id: fos_user.user_provider.username
firewalls:
main:
pattern: ^/
form_login:
provider: fos_userbundle
csrf_provider: form.csrf_provider
logout: true
anonymous: true
access_control:
- { path: ^admin/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^admin/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/admin/, role: ROLE_ADMIN }
的routing.yml
pwd_admin:
resource: "@PWDAdminBundle/Resources/config/routing.yml"
prefix: /admin
pwd_website:
resource: "@PWDWebsiteBundle/Resources/config/routing.yml"
prefix: /
fos_js_routing:
resource: "@FOSJsRoutingBundle/Resources/config/routing/routing.xml"
fos_user_security:
resource: "@FOSUserBundle/Resources/config/routing/security.xml"
fos_user_profile:
resource: "@FOSUserBundle/Resources/config/routing/profile.xml"
prefix: /profile
fos_user_register:
resource: "@FOSUserBundle/Resources/config/routing/registration.xml"
prefix: /admin/register
fos_user_resetting:
resource: "@FOSUserBundle/Resources/config/routing/resetting.xml"
prefix: /resetting
fos_user_change_password:
resource: "@FOSUserBundle/Resources/config/routing/change_password.xml"
prefix: /profile
尝试访问 / admin / login 时出现以下错误
No route found for "GET /admin/login
编辑:路线
fos_user_security_login ANY ANY ANY /login
fos_user_security_check POST ANY ANY /login_check
fos_user_security_logout ANY ANY ANY /logout
fos_user_profile_show GET ANY ANY /profile/
fos_user_profile_edit ANY ANY ANY /profile/edit
fos_user_registration_register ANY ANY ANY /admin/register/
答案 0 :(得分:3)
我遇到了和你一样的问题,下一个解决方案让我看到了登录页面。
尝试将前缀添加到fos_user_security路径
fos_user_security:
resource: "@FOSUserBundle/Resources/config/routing/security.xml"
prefix: admin
希望这有帮助。您可能会进一步遇到一些访问问题,我还没有解决方案,但也许您可以找到自己的解决方案。祝你好运,也许你会与我们分享解决方案,那将是非常好的
玩得开心。
答案 1 :(得分:2)
您需要将security.yml更改为:
security:
firewalls:
main:
form_login:
login_path: /admin/login