【发布时间】:2021-11-11 05:35:29
【问题描述】:
在生产缓存清除期间,我收到此消息:“App\Entity\Evenement”类中方法“setImageFile”中参数“imageFile”的类型提示无效。我按照 github“基本用法”上的 VichUploaderBundle 文档的说明进行操作。 感谢您的帮助!
实体代码下方:
<?php
namespace App\Entity;
use App\Repository\EvenementRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\component\HttpFoundation\File\File;
use Symfony\component\HttpFoundation\File\UploadedFile;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
/**
* @ORM\Entity(repositoryClass=EvenementRepository::class)
* @vich\Uploadable
*/
class Evenement
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*
*/
private $titre;
/**
* @ORM\Column(type="string", length=2000, nullable=true)
*/
private $description;
/**
* @ORM\Column(type="string", length=500, nullable=true)
* @Assert\Url()
*/
private $visuel;
/**
* @Vich\UploadableField(mapping="evenement", fileNameProperty="imageName")
* @var File|null
*/
private $imageFile;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @var string|null
*/
private $imageName;
/**
* @ORM\Column(type="datetime")
*
* @var \DateTimeInterface|null
*/
private $updatedAt;
/**
* @ORM\Column(type="string", length=500, nullable=true)
*/
private $tarifs;
/**
* @ORM\Column(type="datetime")
*/
private $date;
/**
* @ORM\ManyToMany(targetEntity=Film::class, inversedBy="evenements")
*/
private $films;
/**
* @ORM\Column(type="date", nullable=true)
*/
private $dateFin;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $video;
public function __construct()
{
$this->films = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getTitre(): ?string
{
return $this->titre;
}
public function setTitre(string $titre): self
{
$this->titre = $titre;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
public function getVisuel(): ?string
{
return $this->visuel;
}
public function setVisuel(?string $visuel): self
{
$this->visuel = $visuel;
return $this;
}
public function getTarifs(): ?string
{
return $this->tarifs;
}
public function setTarifs(?string $tarifs): self
{
$this->tarifs = $tarifs;
return $this;
}
public function getDate(): ?\DateTimeInterface
{
return $this->date;
}
public function setDate(\DateTimeInterface $date): self
{
$this->date = $date;
return $this;
}
/**
* @return Collection|Film[]
*/
public function getFilms(): Collection
{
return $this->films;
}
public function addFilm(Film $film): self
{
if (!$this->films->contains($film)) {
$this->films[] = $film;
}
return $this;
}
public function removeFilm(Film $film): self
{
$this->films->removeElement($film);
return $this;
}
public function getDateFin(): ?\DateTimeInterface
{
return $this->dateFin;
}
public function setDateFin(?\DateTimeInterface $dateFin): self
{
$this->dateFin = $dateFin;
return $this;
}
public function getVideo(): ?string
{
return $this->video;
}
public function setVideo(?string $video): self
{
$this->video = $video;
return $this;
}
/**
* 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.
*
* @param File|\Symfony\Component\HttpFoundation\File\UploadedFile|null $imageFile
*/
public function setImageFile(?File $imageFile = null): void
{
$this->imageFile = $imageFile;
if (null !== $imageFile) {
// 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();
}
}
public function getImageFile(): ?File
{
return $this->imageFile;
}
public function setImageName(?string $imageName): void
{
$this->imageName = $imageName;
}
public function getImageName(): ?string
{
return $this->imageName;
}
}
【问题讨论】:
-
你好 Olivv,请尝试清除 dev mod 的缓存
-
你好,Ravi,dev mod 的缓存清除在本地和服务器上工作,但 prod mod 的缓存清除在本地和服务器上不起作用。
-
您在产品服务器上尝试过
rm -rf var/cache/*吗? -
它以这种方式工作。在拥有 "rm -rf var/cache/*" 之后,我还必须上传代理目录。但是现在,如何让“php bin/console cache:clear --env=prod”命令再次工作?
-
在
rm -rf /var/cache/*之后尝试php bin/console cache:clear --env=prod命令
标签: symfony parameters production-environment type-hinting vichuploaderbundle