简体   繁体   English

在Symfony2中使用带有KnpGaufrette和Doctrine的VichUploader时的循环引用

[英]Circular reference when using VichUploader with KnpGaufrette and Doctrine in Symfony2

I tried to use the following setup in my Symfony2 project: 我尝试在Symfony2项目中使用以下设置:

Problem: As soon as i try to use the Gaufrette storage adapter "doctrine_dbal" I get the following error: 问题:一旦我尝试使用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".  

The problem occurs as soon as Symfony tries to check the configuration, eg on 一旦Symfony尝试检查配置,就会出现问题,例如

app/console cache:clear

How can I resolve this issue? 我该如何解决这个问题?

My Setup 我的设置

My project setup is the default setup of symfony/framework-standard-edition with version 2.5.* without AcmeDemo Bundle. 我的项目设置是symfony/framework-standard-edition的默认设置,版本为2.5.*没有AcmeDemo Bundle。

I simply did add the Bundles via Composer: 我只是通过Composer添加了Bundles:

composer require knplabs/knp-gaufrette-bundle vich/uploader-bundle

... added them to AppKernel's registerBundles() : ...将它们添加到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
    );
//...

... and added the following configuration to config.yml , which is based on the docs VichUploader with Gaufrette and KnpGaufrette with Doctrine DBAL : ...并将以下配置添加到config.yml ,该配置基于带有Gaufrette的Docs VichUploader带有Doctrine DBAL的 KnpGaufrette

# ...
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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM