配置Gedmo软删除时执行cache:clear命令报错求助
问题:配置Gedmo软删除后执行
cache:clear报错 问题场景
尝试在doctrine.yaml中配置Gedmo软删除,配置内容如下:
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: default_entity_manager: default 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 filters: softdeleteable: class: Gedmo\SoftDeleteable\Filter\SoftDeleteableFilter mappings: translatable: type: attribute # or annotation or xml alias: Gedmo prefix: Gedmo\Translatable\Entity # make sure vendor library location is correct dir: "%kernel.project_dir%/vendor/gedmo/doctrine-extensions/src/Translatable/Entity" Gedmo: type: annotation prefix: Gedmo\SoftDeleteable dir: '%kernel.project_dir%/vendor/gedmo/doctrine-extensions/src/SoftDeleteable' alias: Gedmo is_bundle: false App: type: attribute is_bundle: false dir: '%kernel.project_dir%/src/Entity' prefix: 'App\Entity' alias: App 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
执行命令php bin/console cache:clear时出现错误:
仅可通过DoctrineBundle配置"xml"、"yml"、"php"、"staticphp"或"attribute"类型的元数据驱动。如需配置其他驱动,请自行创建Bundle,或通过向"doctrine.orm.default_metadata_driver"服务定义添加新驱动来注册。
已确认Composer中相关依赖均已安装,询问配置错误点。
错误原因
配置中Gedmo映射块的type: annotation不符合当前DoctrineBundle支持的元数据驱动类型列表,当前版本的DoctrineBundle已不再直接支持annotation作为驱动类型。
解决方案
将Gedmo软删除的映射类型改为attribute(Gedmo Doctrine Extensions已支持Attribute注解),修改后的mappings部分配置如下:
mappings: translatable: type: attribute # or annotation or xml alias: Gedmo prefix: Gedmo\Translatable\Entity # make sure vendor library location is correct dir: "%kernel.project_dir%/vendor/gedmo/doctrine-extensions/src/Translatable/Entity" Gedmo: type: attribute prefix: Gedmo\SoftDeleteable dir: '%kernel.project_dir%/vendor/gedmo/doctrine-extensions/src/SoftDeleteable' alias: Gedmo is_bundle: false App: type: attribute is_bundle: false dir: '%kernel.project_dir%/src/Entity' prefix: 'App\Entity' alias: App
修改后重新执行php bin/console cache:clear即可解决该错误。
内容的提问来源于stack exchange,提问作者Sasha
相关产品推荐
相关产品推荐

