|
- <?php
-
- namespace Lc\ShopBundle\Model;
-
- use Doctrine\ORM\Mapping as ORM;
- use Symfony\Component\HttpFoundation\File\File;
-
-
- trait ImageTrait
- {
- /**
- * @ORM\Column(type="string", length=255, nullable=true)
- */
- protected $image;
-
- /**
- * @Vich\UploadableField(mapping="images", fileNameProperty="image")
- * @var File
- */
- protected $imageFile;
-
- public function setImageFile(File $image = null)
- {
- $this->imageFile = $image;
-
- // VERY IMPORTANT:
- // 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
- if ($image) {
- // if 'updatedAt' is not defined in your entity, use another property
- $this->updatedAt = new \DateTime('now');
- }
- }
-
- public function getImageFile()
- {
- return $this->imageFile;
- }
-
- public function getImage(): ?string
- {
- return $this->image;
- }
-
- public function setImage(?string $image): self
- {
- $this->image = $image;
-
- return $this;
- }
-
-
- }
|