Vichuploaderbundle: Mapping not found for field

Created on 7 Dec 2018  路  3Comments  路  Source: dustin10/VichUploaderBundle

| Q | A
|------------| -----
| Version | 1.4.2

Support Question

Hello,

I have a very common problem but, after reading all that I could find at StackOverflow and after reading all closed issues here, it seems that my problem persists or I'm terribly misunderstanding the documentation.

According to the documentation here: "Where image is the field name used in your entity where you added the UploadableField annotation/configuration."

Therefore, what my code is doing should work, right?

Config

vich_uploader:
    db_driver: orm
    mappings:
        featured_images:
            uri_prefix:         /public/featured
            upload_destination: %kernel.root_dir%/../web/public/featured
            inject_on_load:     true

Php:

/**
 * Featured
 *
 * @ORM\Table(name="featured")
 * @ORM\Entity
 * @ORM\HasLifecycleCallbacks
 * @Vich\Uploadable
 */
class Featured {
    /**
     * @Assert\File(
     *     maxSize="5M",
     *     mimeTypes={"image/png", "image/jpeg", "image/pjpeg", "image/gif"}
     * )
     * @Vich\UploadableField(mapping="featured_images", fileNameProperty="imagePath")
     *
     * @var File $image
     */
    protected $image;

Html:

<img style="width: 100%" class="img-responsive" 
src="{{ vich_uploader_asset(item, 'featured_images') }}">

As I understand it, I should use 'featured_images', which is the mapping in the annotation, right?

As a side note, I've cleaned the cache, deleted the cache, re-updated my composer and even restarted my server... I mean, I can assure you guys that it's not related to caches xD

I really want to know this. It was working fine before, but I was using an ultra old version of Vich (I think was 0.1.x) and, since I updated it, I keep getting this error that actually goes away when I use the Object's property instead of the mapped one given in the annotation.

PS: I'm using Symfony 2.8.17, Doctrine ORM 2.5
Thanks in advance!

Support

Most helpful comment

I think that you should check docs related to your version.
In your case https://github.com/dustin10/VichUploaderBundle/blob/1.4.2/Resources/doc/generating_urls.md should be fine
Of course, upgrading to an actively supported version (both of this bundle and of Symfony) would be the best option

All 3 comments

I think that you should check docs related to your version.
In your case https://github.com/dustin10/VichUploaderBundle/blob/1.4.2/Resources/doc/generating_urls.md should be fine
Of course, upgrading to an actively supported version (both of this bundle and of Symfony) would be the best option

Yeah, since it's an old project of my company, I'll try to update it as time goes by. But unfortunately we're also needing an update in something else and I decided to update some packages. But I stumbled on this error, even though I know it was working before.

Then, reading the documentation (even in the 1.4.2), it says I could use the name given when creating the map. But it only worked with the name/property of the object itself, not the mapped one.

I just found it pretty strange, since every single place says the way I showed above is the correct way =X

Anyway, thanks for the answer. I'll keep using "image" for now then...

All can I suggest here is to look to BC of 0.13.0.
If you can't make it work, the only possible solutions are to revert to your old working version or to upgrade to the latest (that is currently supported)

Was this page helpful?
0 / 5 - 0 ratings