我尝试在我的Symfony2项目中使用以下设置:
- 用于处理文件上传的VichUploader捆绑包
- KnpGaufrette 捆绑包,应由 VichUploader 用作存储适配器
问题:一旦我尝试使用Gaufrette存储适配器"doctrine_dbal",我就会收到以下错误:
[SymfonyComponentDependencyInjectionExceptionServiceCircularReferenceException]
Circular reference detected for service "doctrine.dbal.default_connection", path: "doctrine.orm.default_entity_manager -> doctrine.dbal.default_connection -> vich_uploader.upload_handler -> vich_uploader.storage.gaufrette -> knp_gaufrette.filesystem_map -> gaufrette.storage_fs_filesystem".
一旦Symfony尝试检查配置,例如
在app/console cache:clear
如何解决此问题?
我的设置
我的项目设置是具有版本2.5.*
的symfony/framework-standard-edition
的默认设置,没有AcmeDemo Bundle。
我只是通过作曲家添加了捆绑包:
composer require knplabs/knp-gaufrette-bundle vich/uploader-bundle
。将它们添加到AppKernel的registerBundles()
:
//...
$bundles = array(
new SymfonyBundleFrameworkBundleFrameworkBundle(),
new SymfonyBundleSecurityBundleSecurityBundle(),
new SymfonyBundleTwigBundleTwigBundle(),
new SymfonyBundleMonologBundleMonologBundle(),
new SymfonyBundleSwiftmailerBundleSwiftmailerBundle(),
new SymfonyBundleAsseticBundleAsseticBundle(),
new DoctrineBundleDoctrineBundleDoctrineBundle(),
new SensioBundleFrameworkExtraBundleSensioFrameworkExtraBundle(),
new AppBundleAppBundle(),
new VichUploaderBundleVichUploaderBundle(), //NEW
new KnpBundleGaufretteBundleKnpGaufretteBundle(), //NEW
);
//...
。并将以下配置添加到 config.yml
中,该配置基于文档 VichUploader with Gaufrette 和 KnpGaufrette with Doctrine DBAL:
# ...
knp_gaufrette:
stream_wrapper: ~
adapters:
storage_adapter:
doctrine_dbal:
connection_name: default
table: data_storage
columns:
key: id
content: file
mtime: mtime
checksum: checksum
filesystems:
storage_fs:
adapter: storage_adapter
vich_uploader:
db_driver: orm
storage: gaufrette
mappings:
storage:
uri_prefix: /images/products
upload_destination: storage_fs
这是版本 0.14.0 (https://github.com/dustin10/VichUploaderBundle/issues/370) 中的一个错误,在此提交中已修复:https://github.com/dustin10/VichUploaderBundle/commit/4abf4180afaf318a66d3e34736c5a14aa0883bd3