Symfony:vich/uploader bundle 1.6.2:config yml

Symfony:vich/uploader bundle 1.6.2:config yml,symfony,vichuploaderbundle,Symfony,Vichuploaderbundle,我尝试只使用YML配置Vich,并面临一个问题。 我创建声明文件(路径:src/My/GreatBundle/Resources/config/vich_uploader/Media.yml): 创建实体媒体(路径:src/My/GreatBundle/entity/media.php): 很明显,我有清晰的缓存 编辑1:config.yml vich_uploader: db_driver: orm mappings: image: ur

我尝试只使用YML配置Vich,并面临一个问题。 我创建声明文件(路径:src/My/GreatBundle/Resources/config/vich_uploader/Media.yml):

创建实体媒体(路径:src/My/GreatBundle/entity/media.php):

很明显,我有清晰的缓存

编辑1:config.yml

vich_uploader:
    db_driver: orm
    mappings:
        image:
            uri_prefix: /media
            upload_destination: '%kernel.root_dir%/../uploads/media'
            delete_on_remove: true
            delete_on_update: false
            inject_on_load: false
            namer:
                service: vich_uploader.namer_property
                options: { property: 'id' }

更新:

正如我所看到的,在您的配置中,您的filename\u属性被称为file\u name,但您的表单使用propertyimage作为filename属性

另外,在
Media.yml
文件中,您正在使用名为image\u mapping的映射名,但在
config.yml
中,您的映射名为image

我不知道你为什么要避免注释,但是当你使用注释时,生活会变得容易得多:)


有一个与此相关的问题,请检查

是否可以添加config.yml?config.yml add。我试图在vich_uploader/Media.yml中设置无效语法,但如果它没有加载(尽管我尊重文档中的目录名),我尝试编写无效语法,但yml似乎无法识别!:(为了清晰起见,我更喜欢使用YML,因为阅读注释就像阅读外来语言一样,我从YML开始,我认为继续使用YML更为一致。
<?php
namespace My\GreatBundle\Entity;

use Symfony\Component\HttpFoundation\File\File;

class Media{
    private $id;
    public function getId(){
        return $this->id;
    }

    protected $file_name;
    protected $image;

    public function setFileName($fileName){
        $this->file_name = $fileName;

        return $this;
    }

    public function getFileName(){
        return $this->file_name;
    }

    public function setImage(File $image){
        $this->image = $image;

        return $this;
    }

    public function getImage(){
        return $this->image;
    }
}
<?php
namespace My\GreatBundle\Entity\Form\Type;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

use Symfony\Component\Form\ChoiceList\Loader\CallbackChoiceLoader;

use My\GreatBundle\Entity\Media;

use Vich\UploaderBundle\Form\Type\VichImageType;

class MediaType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options){
        $builder
            ->add('image', VichImageType::class, [
                'required' => false,
            ])
        ;
    }

    public function configureOptions(OptionsResolver $resolver){
        $resolver->setDefaults(array(
             'data_class' => Media::class,
        ));
    }

    public function getName(){
        return 'my_great_type_media';
    }
}
The class "My\GreatBundle\Entity\Media" is not uploadable. If you use annotations to configure VichUploaderBundle, you probably just forgot to add `@Vich\Uploadable` on top of your entity. If you don't use annotations, check that the configuration files are in the right place. In both cases, clearing the cache can also solve the issue.
vich_uploader:
    db_driver: orm
    mappings:
        image:
            uri_prefix: /media
            upload_destination: '%kernel.root_dir%/../uploads/media'
            delete_on_remove: true
            delete_on_update: false
            inject_on_load: false
            namer:
                service: vich_uploader.namer_property
                options: { property: 'id' }