我的项目中有 2 个捆绑包:
- src/韩国/AlmacenBundle
- src/Galvez/RepuestosBundle
每个都有自己的数据库
- korea_motos -> AlmacenBundle
- galvez_motos -> RepuestosBundle
实际上我的 security.yml 只有一个提供者:
providers:
korea:
entity: { class: Korea\AlmacenBundle\Entity\Usuario, property: username }
如您所见,两个捆绑包都由同一个表进行身份验证:Usuario,在 korea_motos
表:Usuario(korea_motos 数据库)
--ID--|----用户名----|---------捆绑包---
--1-----|-------------管理员----|------ ---AlmacenBundle------
--2-----|-------------管理员----|------ ---RepuestosBundle-------
现在我想验证用户,对于 RepuestosBundle,在 galvez_motos 中有一个表 Usuario,删除上一个表中的“bundle”列。
问题出在 security.yml 文件中。如果我这样做:
providers:
korea:
entity: { class: Korea\AlmacenBundle\Entity\Usuario, property: username }
galvez:
entity: { class: Galvez\RepuestosBundle\Entity\Usuario, property: username }
Symfony 启动异常:
The class 'Galvez\RepuestosBundle\Entity\Usuario' was not found in the chain configured namespaces Korea\AlmacenBundle\Entity
我尝试使用 2 个提供程序,每个捆绑包一个表.. 这可能吗?
文件:security.yml
jms_security_extra:
secure_all_services: false
expressions: true
安全性:编码器:Korea\AlmacenBundle\Entity\Usuario:算法:sha1 encode_as_base64:错误迭代:1 Galvez\RepuestosBundle\Entity\Usuario:算法:sha1 encode_as_base64:错误迭代:1
role_hierarchy:
ROLE_ADMIN: ROLE_USER
ROLE_SUPER_ADMIN: [ ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH ]
providers:
korea:
entity: { class: Korea\AlmacenBundle\Entity\Usuario, property: username }
galvez:
entity: { class: Galvez\RepuestosBundle\Entity\Usuario, property: username }
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
login:
pattern: ^/demo/secured/login$
security: false
secured_area:
pattern: ^/
anonymous: ~
access_denied_handler: accessdenied_handler
form_login:
login_path: /login
check_path: /login_check
default_target_path: /redirect
always_use_default_target_path: true
logout:
path: /logout
target: /login
#anonymous: ~
#http_basic:
# realm: "Secured Demo Area"
access_control:
- { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/redirect, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/galvez, roles: ROLE_ADMIN_GALVEZ }
- { path: ^/, roles: ROLE_ADMIN_KOREA }
config.yml -- 不能全部复制/粘贴:(
doctrine:
dbal:
default_connection: default
connections:
default:
driver: "%database_driver%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
host: "%database_host%"
port: "%database_port%"
charset: UTF8
galvez:
driver: %database_driver%
dbname: %database_name2%
user: %database_user2%
password: %database_password2%
host: %database_host%
port: %database_port%
charset: UTF8
orm:
default_entity_manager: default
entity_managers:
default:
connection: default
mappings:
AlmacenBundle: ~
galvez:
connection: galvez
mappings:
RepuestosBundle: ~
参数.yml
parameters:
database_driver: pdo_mysql
database_host: localhost
database_port: null
database_name: korea_motos
database_user: root
database_password:
mailer_transport: smtp
mailer_host: localhost
mailer_user: null
mailer_password: null
locale: en
secret: 5f7ac4e7c2b38d6dbe55a1f05bee2b02
database_path: null
database_name2: galvez_motos
database_user2: root
database_password2:
PD:对不起我的英语:S