I´m trying to implement a DirectoryNamer, but unfortunately this results in an error message and I don´t know what to do next.
The Controller (excerpt):
if ($form->isSubmitted() && $form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($image);
$em->flush();
//...
}
The DirectoryNamer Service Class:
use Vich\UploaderBundle\Naming\DirectoryNamerInterface;
class ArtistDirectoryNamer implements DirectoryNamerInterface
{
public function directoryName($image, PropertyMapping $mapping) {
return $image->getArtist()->getId();
}
}
The VichUploader Configuration:
vich_uploader:
db_driver: orm
mappings:
upload_artists:
uri_prefix: /upload/artists
upload_destination: %kernel.root_dir%/../web/upload/artists
directory_namer: macms_admin.artist_directory_namer
namer: vich_uploader.namer_uniqid
inject_on_load: false
delete_on_update: true
delete_on_remove: true
... and the reulting Error Message:
Compile Error: Declaration of ArtistDirectoryNamer::directoryName() must be compatible with Vich\UploaderBundle\Naming\DirectoryNamerInterface::directoryName($object, Vich\UploaderBundle\Mapping\PropertyMapping $mapping)
What´s wrong with my code? Until I´ve implemented the DirectoryNamer, the upload worked fine and the files have been stored in '/upload/artists'.
Any hints? Thanks in advance!
Maybe you forgot the use
statement for the Vich\UploaderBundle\Mapping\PropertyMapping
class?