我有一个问题,我想在Symfony框架中制作两个不同的登录表单。 我做了一个App \ Entity \ Admin和App \ Entity \ User类,但是Symfony防火墙没有正确分配它的URL。
示例1:
#not working (Main == user)
Admin pattern: ^/*
Main pattern: ^/*
示例2:
#working, but not good (Main == user)
Admin pattern: ^/admin/*
Main pattern: ^/*
# The index or other front page of site not working twig {% if is_granted('ROLE_ADMIN') %},
# because it's out of range. (But good the 'ROLE_USER')...
如果用于一个表的ADMIN和USER数据以及一个防火墙或chain_provider,它可以工作,但是,我不想将用户和管理员存储在一个表中。我需要两种不同的形式,并且我想最先成为用户防火墙。
security:
providers:
db_admin:
entity:
class: App\Entity\Admin
property: username
db_username:
entity:
class: App\Entity\User
property: username
encoders:
App\Entity\User:
algorithm: bcrypt
App\Entity\Admin:
algorithm: bcrypt
Symfony\Component\Security\Core\User\User:
algorithm: bcrypt
cost: 12
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
admin:
pattern: ^/*
security: true
anonymous: true
provider: db_admin
form_login:
login_path: /admin/login
check_path: /admin/login
logout:
path: /logout
target: /
context: my_context
main:
pattern: ^/*
anonymous: true
provider: db_username
form_login:
login_path: /login
check_path: /login
always_use_default_target_path: true
logout:
path: /logout
target: /
access_control:
- { path: ^/admin/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/admin, roles: ROLE_ADMIN }
- { path: ^/profile, roles: ROLE_USER }
- { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/registration, roles: IS_AUTHENTICATED_ANONYMOUSLY }
谢谢!