I try to configure Vich using only YML and face to a problem. I create declaration file (path: src/My/GreatBundle/Resources/config/vich_uploader/Media.yml) :
My\GreatBundle\Entity\Media:
image:
mapping: image_mapping
filename_property: file_name
Create the entity media (path: src/My/GreatBundle/Entity/Media.php) :
<?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;
}
}
And finally create form (path: src/My/GreatBundle/Entity/Form/Type/MediaType.php) :
<?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';
}
}
An idea what is miss ? I have this message :
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.
Obviously I have clear cache.
Edit 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' }