使用Gedmo Loggable还原实体遇Doctrine仓库错误,求配置方案
问题:还原Loggable实体时出现类未找到错误
我尝试还原一个实体,执行了以下代码:
// use Gedmo\Loggable\Entity\LogEntry; //... $repo = $this->entityManager->getRepository(LogEntry::class); $repo->revert($pizza, 1); // ...
执行后出现错误:
The class 'Gedmo\Loggable\Entity\LogEntry' was not found in the chain configured namespaces App\Entity
这是Doctrine配置问题,以下是我的config/packages/doctrine.yaml文件内容:
doctrine: dbal: url: '%env(resolve:DATABASE_URL)%' # IMPORTANT: You MUST configure your server version, # either here or in the DATABASE_URL env var (see .env file) #server_version: '16' profiling_collect_backtrace: '%kernel.debug%' use_savepoints: true orm: auto_generate_proxy_classes: true enable_lazy_ghost_objects: true report_fields_where_declared: true validate_xml_mapping: true naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware auto_mapping: true mappings: App: type: attribute is_bundle: false dir: '%kernel.project_dir%/src/Entity' prefix: 'App\Entity' alias: App filters: # soft deletion softdeleteable: class: Gedmo\SoftDeleteable\Filter\SoftDeleteableFilter enabled: true controller_resolver: auto_mapping: false when@test: doctrine: dbal: # "TEST_TOKEN" is typically set by ParaTest dbname_suffix: '_test%env(default::TEST_TOKEN)%' when@prod: doctrine: orm: auto_generate_proxy_classes: false proxy_dir: '%kernel.build_dir%/doctrine/orm/Proxies' query_cache_driver: type: pool pool: doctrine.system_cache_pool result_cache_driver: type: pool pool: doctrine.result_cache_pool framework: cache: pools: doctrine.result_cache_pool: adapter: cache.app doctrine.system_cache_pool: adapter: cache.system
使用版本:
- Symfony 6.4
- Doctrine ORM 2.19.3
- Doctrine Bundle 2.12
- Doctrine Extension Bundle 1.11.0
解决方案
需要在Doctrine ORM的mappings节点下添加Gedmo Loggable实体的映射配置,让Doctrine能够识别Gedmo\Loggable\Entity\LogEntry类。
修改config/packages/doctrine.yaml中的orm.mappings部分,新增Gedmo的映射配置:
mappings: App: type: attribute is_bundle: false dir: '%kernel.project_dir%/src/Entity' prefix: 'App\Entity' alias: App GedmoLoggable: type: attribute is_bundle: false dir: '%vendor_dir%/gedmo/doctrine-extensions/src/Loggable/Entity' prefix: 'Gedmo\Loggable\Entity' alias: GedmoLoggable
完成配置修改后,执行命令清理Symfony缓存:
php bin/console cache:clear
重新运行还原实体的代码即可解决类未找到的问题。
内容的提问来源于stack exchange,提问作者LucileDT
相关产品推荐
相关产品推荐

