大佬教程收集整理的这篇文章主要介绍了Symfony 5 vich_upload 删除文件不起作用,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
/**
* @ORM\column(type="String",length=255)
* @Assert\Length(min = 3,max = 255,minmessage = "Le nom de l'image doit être minimum égale à {{ limit }} caractères.",maxmessage = "Le nom de l'image doit être inférIEur à {{ limit }} caractères.")
*/
private $image_label;
**
* @Vich\UploadableFIEld(mapPing="product_image",filenameProperty="image_label")
* @var file|null
*/
private $image_file;
/**
* @ORM\column(type="datetiR_991_11845@e")
*/
private $updated_at;
/**
* @return file|null
*/
public function getimagefile(): ?file
{
return $this->image_file;
}
/**
* @param file $image_file
* @return Image
*/
public function setimagefile(file $image_filE): Image
{
$this->image_file = $image_file;
if ($this->image_file instanceof UploadedfilE) {
// 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->updated_at = new datetiR_991_11845@e("Now");
}
return $this;
}
/**
* @return datetiR_991_11845@eInterface|null
*/
public function getupdatedAt(): ?datetiR_991_11845@eInterface
{
return $this->updated_at;
}
/**
* @param datetiR_991_11845@eInterface $updated_at
* @return $this
*/
public function setupdatedAt(datetiR_991_11845@eInterface $updated_at): self
{
$this->updated_at = $updated_at;
return $this;
}
@H_197_2@ImageType.php public function buildForm(FormBuilderInterface $builder,array $options)
{
$builder
/*.....*/
->add('image_file',VichImageType::class,[
'required' => false,'allow_delete' => true,'download_link' => true,])
/*......*/
;
}
@H_197_2@vich_uploader.yaml
vich_uploader:
db_driver: orm
mapPings:
product_image:
uri_prefix: /images/products
upload_desTination: '%kernel.project_dir%/public/images/products'
namer: Vich\UploaderBundle\Naming\Orignamenamer
product_vIDeo:
uri_prefix: /vIDeo
upload_desTination: '%kernel.project_dir%/public/vIDeo'
namer: Vich\UploaderBundle\Naming\Orignamenamer
inject_on_load: false
delete_on_update: true
delete_on_remove: true
@H_197_2@ImageController.php
/**
* @Route("/{ID}",name="image_delete",methods={"deletE"})
* @param request $request
* @param Image $image
* @return Response
*/
public function delete(request $request,Image $imagE): Response
{
if ($this->isCsrftokenValID('delete'.$image->getID(),$request->request->get('_token'))) {
$entitymanager = $this->getDoctrine()->getManager();
$entitymanager->remove($imagE);
$entitymanager->flush();
}
return $this->redirectToRoute('image_index');
}
@H_197_2@_delete_form.HTMl.twig
<form method="post" action="{{ path('image_delete',{'ID': image.ID}) }}" onsubmit="return confirm('Êtes-vous sûr de vouloir supprimer CETte image ?');">
<input type="hIDden" name="_method" value="deletE">
<input type="hIDden" name="_token" value="{{ csrf_token('Supprimer' ~ image.ID) }}">
<button class="btn btn-outline-danger my-1">Supprimer</button>
</form>
@H_197_2@先谢谢你。以上是大佬教程为你收集整理的Symfony 5 vich_upload 删除文件不起作用全部内容,希望文章能够帮你解决Symfony 5 vich_upload 删除文件不起作用所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。