config.yml
vich_uploader:
db_driver: orm
mappings:
team_image:
uri_prefix: /uploads/logos
upload_destination: '%kernel.root_dir%/../web/uploads/logos'
inject_on_load: false
delete_on_update: true
delete_on_remove: true
Сущность
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Vich\UploaderBundle\Entity\File as EmbeddedFile;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
/**
* @ORM\Entity
* @Vich\Uploadable
* @ORM\Table(name="team")
*/
class Team
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
// ..... other fields
/**
* NOTE: This is not a mapped field of entity metadata, just a simple property.
*
* @Vich\UploadableField(mapping="team_image", fileNameProperty="image.name", size="image.size", mimeType="image.mimeType", originalName="image.originalName")
*
* <strong i="8">@var</strong> File
*/
private $imageFile;
/**
* @ORM\Embedded(class="Vich\UploaderBundle\Entity\File")
*
* <strong i="9">@var</strong> EmbeddedFile
*/
private $image;
/**
* @ORM\Column(type="datetime")
*
* <strong i="10">@var</strong> \DateTime
*/
private $updatedAt;
/**
* If manually uploading a file (i.e. not using Symfony Form) ensure an instance
* of 'UploadedFile' is injected into this setter to trigger the update. If this
* bundle's configuration parameter 'inject_on_load' is set to 'true' this setter
* must be able to accept an instance of 'File' as the bundle will inject one here
* during Doctrine hydration.
*
* <strong i="11">@param</strong> File|UploadedFile $image
*/
public function setImageFile(File $image = null)
{
$this->imageFile = $image;
if ($image) {
// It is required that at least one field changes if you are using doctrine
// otherwise the event listeners won't be called and the file is lost
$this->updatedAt = new \DateTimeImmutable();
}
}
/**
* <strong i="12">@return</strong> File|null
*/
public function getImageFile()
{
return $this->imageFile;
}
/**
* <strong i="13">@param</strong> EmbeddedFile $image
*/
public function setImage(EmbeddedFile $image)
{
$this->image = $image;
}
/**
* <strong i="14">@return</strong> EmbeddedFile
*/
public function getImage()
{
return $this->image;
}
}
Я не понимаю, почему я не могу найти отображение, мне нужна помощь, пожалуйста
Я не могу смешать нормальную сущность с этим ??? Мне нужна только сущность для картинок?
Решить я нахожу проблему в форме
Для тех, кто приходит сюда с такой же ошибкой:
В своей форме вы должны использовать свойство $imageFile
вместо $image
one.
@diegocastro
У меня такая же проблема
Какое точное решение? Я использую easyAdminBundle.
Спасибо
@ stef59100 Я не использую EasyAdminBundle, поэтому не могу вам здесь помочь. Есть ли место, где вы определяете форму? Если это так, не сопоставляйте форму со свойством $image
, используйте вместо этого $imageFile
.
У меня возникла та же проблема, что и у @Vich\Uploadable
в верхней части моего файла объекта.
Самый полезный комментарий
Для тех, кто приходит сюда с такой же ошибкой:
В своей форме вы должны использовать свойство
$imageFile
вместо$image
one.