【问题标题】:Symfony 4: Direct Users to different pages depending on RoleSymfony 4:根据角色将用户引导到不同的页面
【发布时间】:2019-03-03 11:19:47
【问题描述】:

事情就是这样,我创建了一个 symfony 4 应用程序,它有 2 个角色:ROLE_USER 和 ROLE_Admin,有 2 个页面:用户页面和管理员页面。 我对 symfony 完全陌生,文档没有帮助。 现在我希望登录屏幕将每个用户引导到他各自的页面。我正在使用默认的 security.yml,它指向默认主页。 这是我的 security.yaml 文件:

security:
# https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers
providers:
    hamda:
        entity:
            class: App\Entity\User
            property: username

encoders:
    App\Entity\User: bcrypt

firewalls:
    dev:
        pattern: ^/(_(profiler|wdt)|css|images|js)/
        security: false
    main:
        anonymous: true
        provider: hamda
        form_login:
            login_path: login
            check_path: login
            default_target_path: /home


# Easy way to control access for large sections of your site
# Note: Only the *first* access control that matches will be used
access_control:
    - { path: ^/admin, roles: ROLE_ADMIN }

【问题讨论】:

标签: symfony


【解决方案1】:

这可能是在 symfony 4 中解决这个问题的正确方法:

https://stackoverflow.com/a/41441034/9757801

因此,使用自定义防护很容易实现这一点。

【讨论】:

  • 啊,谢谢你告诉我关于警卫的事情,我不知道,我想我会用它
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-02-12
  • 1970-01-01
  • 1970-01-01
  • 2020-07-05
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多