Search code examples
doctrine-ormimage-uploadingsonata-adminsymfony-3.2

Image Upload Issue with Symfony3, Doctrine 2 and Sonata Admin Bundle


i will upload multipe Images in an Sonta Admin Frontend with and Sonata_Form_Collection.

The upload is the following error in the log:

[2017-06-24 13:06:19] request.CRITICAL: Uncaught PHP Exception Symfony\Component\PropertyAccess\Exception\InvalidArgumentException: "Expected argument of type "AppBundle\Entity\Picture", "array" given" at /Users/Christian/Sites/zeltplatz/vendor/symfony/symfony/src/Symfony/Component/PropertyAccess/PropertyAccessor.php line 275 {"exception":"[object] (Symfony\\Component\\PropertyAccess\\Exception\\InvalidArgumentException(code: 0): Expected argument of type \"AppBundle\\Entity\\Picture\", \"array\" given at /Users/Christian/Sites/zeltplatz/vendor/symfony/symfony/src/Symfony/Component/PropertyAccess/PropertyAccessor.php:275)"} []

Here my Campground Entity:

https://pastebin.com/VWxRY9yq

and my Picture Entity:

https://pastebin.com/e0myy9b9

Also my Sonata Campground Admin:

https://pastebin.com/q3xnu6Ts

and Sonata Picture Admin:

https://pastebin.com/sJwaNUdi

The goal is that I can save several pictures for a campground.

Thanks for feedback and ideas


Solution

  • Here you have a problem with the data type, you need instance of Picture and you give array(of pictures i think). Maybe try add pictures one after the other in loop.