在 Symfony2 中将 VichUploader 与 KnpGaufrette 和 Doctrine 一起使用时的循环引用
Circular reference when using VichUploader with KnpGaufrette and Doctrine in Symfony2
我尝试在我的 Symfony2 项目中使用以下设置:
- VichUploader Bundle 用于处理文件上传
- KnpGaufrette Bundle 应该被 VichUploader 用作存储适配器
问题: 当我尝试使用 Gaufrette 存储适配器时 "doctrine_dbal" 我收到以下错误:
[Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException]
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
我该如何解决这个问题?
我的设置
我的项目设置是 symfony/framework-standard-edition
的默认设置,版本 2.5.*
没有 AcmeDemo Bundle。
我只是通过 Composer 添加了捆绑包:
composer require knplabs/knp-gaufrette-bundle vich/uploader-bundle
...将它们添加到 AppKernel 的 registerBundles()
:
//...
$bundles = array(
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new Symfony\Bundle\SecurityBundle\SecurityBundle(),
new Symfony\Bundle\TwigBundle\TwigBundle(),
new Symfony\Bundle\MonologBundle\MonologBundle(),
new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
new Symfony\Bundle\AsseticBundle\AsseticBundle(),
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
new AppBundle\AppBundle(),
new Vich\UploaderBundle\VichUploaderBundle(), //NEW
new Knp\Bundle\GaufretteBundle\KnpGaufretteBundle(), //NEW
);
//...
... 并将以下配置添加到 config.yml
,这是基于文档 VichUploader with Gaufrette and 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
我尝试在我的 Symfony2 项目中使用以下设置:
- VichUploader Bundle 用于处理文件上传
- KnpGaufrette Bundle 应该被 VichUploader 用作存储适配器
问题: 当我尝试使用 Gaufrette 存储适配器时 "doctrine_dbal" 我收到以下错误:
[Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException]
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
我该如何解决这个问题?
我的设置
我的项目设置是 symfony/framework-standard-edition
的默认设置,版本 2.5.*
没有 AcmeDemo Bundle。
我只是通过 Composer 添加了捆绑包:
composer require knplabs/knp-gaufrette-bundle vich/uploader-bundle
...将它们添加到 AppKernel 的 registerBundles()
:
//...
$bundles = array(
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new Symfony\Bundle\SecurityBundle\SecurityBundle(),
new Symfony\Bundle\TwigBundle\TwigBundle(),
new Symfony\Bundle\MonologBundle\MonologBundle(),
new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
new Symfony\Bundle\AsseticBundle\AsseticBundle(),
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
new AppBundle\AppBundle(),
new Vich\UploaderBundle\VichUploaderBundle(), //NEW
new Knp\Bundle\GaufretteBundle\KnpGaufretteBundle(), //NEW
);
//...
... 并将以下配置添加到 config.yml
,这是基于文档 VichUploader with Gaufrette and 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