未返回正确的EntityManager Symfony



我正在实现symfony安全性。我的用户实体在另一个数据库中。我有很多经理。到目前为止,我无法让entitymanager读取User表,在我的情况下,它不是默认的entitymanager。

这是我的安全。yaml

security:
encoders:
AppEntityUser:
id: 'AppSecurityEncoderMyCustomPasswordEncoder'
#app_encoder:
#para oracle
# https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers
providers:
# used to reload user from session & other features (e.g. switch_user)
app_user_provider:
entity:
class: AppEntityTrimuUser
property: email
manager_name: trimu
#https://symfony.com/doc/4.0/security/entity_provider.html
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
main:
anonymous: true
lazy: true
provider: app_user_provider
guard:
authenticators:
- AppSecurityLoginFormAuthenticator
logout:
path: app_logout
#target: app_logout
remember_me:
secret:   '%kernel.secret%'
lifetime: 2592000 # 30 days in seconds
# activate different ways to authenticate
# https://symfony.com/doc/current/security.html#firewalls-authentication
# https://symfony.com/doc/current/security/impersonating_user.html
# switch_user: true
# 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 }
# - { path: ^/profile, roles: ROLE_USER }

这是我的医生。yaml

doctrine:
dbal:
default_connection: default
connections:
default:
# configure these for your database server
driver: 'pdo_mysql'
server_version: '5.7'
charset: utf8mb4
default_table_options:
charset: utf8mb4
collate: utf8mb4_unicode_ci
url: '%env(resolve:DATABASE_URL)%'
trimu:
# configure these for your database server
driver: 'oci8'
server_version: ~
charset: utf8mb4
default_table_options:
charset: utf8mb4
collate: utf8mb4_unicode_ci
url: '%env(resolve:DATABASE_SECURITY_URL)%'
# IMPORTANT: You MUST configure your server version,
# either here or in the DATABASE_URL env var (see .env file)
#server_version: '5.7'
orm:
default_entity_manager: default
#auto_generate_proxy_classes: true
entity_managers:
default:
connection: default
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
mappings:
App:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity'
prefix: 'AppEntity'
alias: App
trimu:
connection: trimu
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
mappings:
App:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity/Trimu'
prefix: 'AppEntityTrimu'
alias: App

正如你所看到的,我的实体App\entity\Trimu\User在其他目录和前缀中。我读过:Symfony 2.8:Doctrine getManagerForClass((没有返回正确的实体管理器,我有同样的问题:getManagerForClass[((方法如何找出哪个实体管理器适合特定类?

谢谢。

已解决,感谢朋友

我更改了所有前缀和所有目录,现在工作正常。

doctrine:
dbal:
default_connection: default
connections:
default:
# configure these for your database server
driver: 'pdo_mysql'
server_version: '5.7'
charset: utf8mb4
default_table_options:
charset: utf8mb4
collate: utf8mb4_unicode_ci
url: '%env(resolve:DATABASE_URL)%'
trimu:
# configure these for your database server
driver: 'oci8'
server_version: ~
charset: utf8mb4
default_table_options:
charset: utf8mb4
collate: utf8mb4_unicode_ci
url: '%env(resolve:DATABASE_SECURITY_URL)%'
# IMPORTANT: You MUST configure your server version,
# either here or in the DATABASE_URL env var (see .env file)
#server_version: '5.7'
orm:
default_entity_manager: default
#auto_generate_proxy_classes: true
entity_managers:
default:
connection: default
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
mappings:
App:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity/Mysql'
prefix: 'AppEntityMysql'
alias: App
trimu:
connection: trimu
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
mappings:
App:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity/Trimu'
prefix: 'AppEntityTrimu'
alias: App

正如Stev所说:您的第一位实体经理负责所有实体,因为:

dir: '%kernel.project_dir%/src/Entity'

您的第一个实体经理覆盖了所有实体,因为:

dir:'%kernel.project_dir%/src/Entity'

更改文件夹结构,使每个EntityManager都有自己的文件夹来查找映射。示例:

entity_managers:
default:
connection: default
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
mappings:
App:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity/App'
prefix: 'AppEntityApp'
alias: App
trimu:
connection: trimu
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
mappings:
App:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity/Trimu'
prefix: 'AppEntityTrimu'
alias: Trimu

相关内容

  • 没有找到相关文章

最新更新