Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 多个上传图像easyadmin存在问题_Php_File_Symfony_Easyadmin - Fatal编程技术网

Php 多个上传图像easyadmin存在问题

Php 多个上传图像easyadmin存在问题,php,file,symfony,easyadmin,Php,File,Symfony,Easyadmin,您好,我在easyadmin多图像上传方面有几个问题。请帮忙。奇怪的是,我的问题主要是蛋糕和蛋糕照片。在easyadmin中,我在蛋糕中添加了几个图像,它们被转换为数组并存储在数据库中。在他们被展示出来之后。至少我计划做的是 下面是Cakes.php实体 <?php namespace App\Entity; use Doctrine\ORM\Mapping as ORM; use Doctrine\Common\Collections\ArrayCollection; use Doc

您好,我在easyadmin多图像上传方面有几个问题。请帮忙。奇怪的是,我的问题主要是蛋糕和蛋糕照片。在easyadmin中,我在蛋糕中添加了几个图像,它们被转换为数组并存储在数据库中。在他们被展示出来之后。至少我计划做的是

下面是Cakes.php实体

<?php

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Vich\UploaderBundle\Entity\File as EmbeddedFile;
use Vich\UploaderBundle\Mapping\Annotation as Vich;

/**
 * @ORM\Entity(repositoryClass="App\Repository\CakesRepository")
 * @Vich\Uploadable
 */
class Cakes
{
    /**
     * @ORM\Id()
     * @ORM\GeneratedValue()
     * @ORM\Column(type="integer")
     */
    private $id;

    /**
     * @ORM\Column(type="string", length=100)
     */
    private $CakeName;

    /**
     * @ORM\Column(type="integer")
     */
    private $CakePrice;

    /**
     * @ORM\Column(type="string", length=255)
     */
    private $Description;

    /**
     * @ORM\Column(type="json")
     */
    private $CakeCategory = [];

    /**
     * @ORM\ManyToMany(targetEntity="Location", mappedBy="Cakes", cascade={"persist"})
     */
    private $AvailableLocation = [];

    /**
     * @ORM\OneToMany(targetEntity="CakePhotos", mappedBy="Cake", cascade={"persist"})
     */
    private $CakePhotos;


    public function __construct()
    {
        $this->AvailableLocation = new ArrayCollection();
        $this->CakePhotos = new ArrayCollection();
    }

    public function getId(): ?int
    {
        return $this->id;
    }

    public function getCakeName(): ?string
    {
        return $this->CakeName;
    }

    public function setCakeName(string $CakeName): self
    {
        $this->CakeName = $CakeName;

        return $this;
    }

    public function getCakePrice(): ?int
    {
        return $this->CakePrice;
    }

    public function setCakePrice(int $CakePrice): self
    {
        $this->CakePrice = $CakePrice;

        return $this;
    }

    public function getDescription(): ?string
    {
        return $this->Description;
    }

    public function setDescription(string $Description): self
    {
        $this->Description = $Description;

        return $this;
    }

    public function getCakeCategory(): ?array
    {
        return $this->CakeCategory;
    }

    public function setCakeCategory(array $CakeCategory): self
    {
        $this->CakeCategory = $CakeCategory;

        return $this;
    }

    /**
     * @return Collection|Location[]
     */
    public function getAvailableLocation(): Collection
    {
        return $this->AvailableLocation;
    }
    public function addAvailableLocation(Location $location): self
    {
        if (!$this->AvailableLocation->contains($location)) {
            $this->AvailableLocation[] = $location;
            $location->addCake($this);
        }
        return $this;
    }
    public function removeAvailableLocation(Location $location): self
    {
        if ($this->AvailableLocation->contains($location)) {
            $this->AvailableLocation->removeElement($location);
            $location->removeCake($this);
        }
        return $this;
    }


    /**
     * @return Collection|CakePhoto[]
     */
    public function getCakePhotos(): Collection
    {
        return $this->CakePhotos;
    }
    public function addCakePhoto(CakePhotos $CakePhotos): self
    {
        if (!$this->CakePhotos->contains($CakePhotos)) {
            $this->CakePhoto[] = $CakePhotos;
            $CakePhotos->setCake($this);
        }
        return $this;
    }
    public function removeCakePhoto(CakePhotos $CakePhotos): self
    {
        if ($this->CakePhotos->contains($CakePhotos)) {
            $this->CakePhotos->removeElement($CakePhotos);
        }
        return $this;
    }

    public function getImageURL(): ?string
    {
        return $this->ImageURL;
    }

    public function setImageURL(string $ImageURL): self
    {
        $this->ImageURL = $ImageURL;

        return $this;
    }
}
    <?php

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\HttpFoundation\File\File;
use Vich\UploaderBundle\Mapping\Annotation as Vich;

/**
 * @ORM\Entity(repositoryClass="App\Repository\CakePhotosRepository")
 * @Vich\Uploadable
 */
class CakePhotos
{
    /**
     * @ORM\Id()
     * @ORM\GeneratedValue()
     * @ORM\Column(type="integer")
     */
    private $id;

    /**
     * @ORM\Column(type="string", length=255, nullable=true)
     */
    private $Image;

    /**
     * @Vich\UploadableField(mapping="cakephotos", fileNameProperty="Image")
     */
    private $ImageFile;

    /**
     * @ORM\ManyToOne(targetEntity="Cakes", inversedBy="CakePhotos")
     */
    private $Cake;


    public function getId(): ?int
    {
        return $this->id;
    }

    public function getImage(): ?string
    {
        return $this->Image;
    }

    public function setImage(?string $Image)
    {
        $this->Image = $Image;

        return $this;
    }
    public function getCake(): ?Cakes
    {
        return $this->Cake;
    }
    public function setCake(?Cake $cake): self
    {
        $this->Cake = $cake;
        return $this;
    }

    public function __toString()
    {
        return $this->Image;
    }

    /**
     * @return mixed
     */
    public function getImageFile()
    {
        return $this->ImageFile;
    }
    /**
     * @param mixed $imageFile
     * @throws \Exception
     */
    public function setImageFile(?File $ImageFile): void
    {
        $this->ImageFile = $ImageFile;
    }
}

你可以通过这样做来解决你的问题

 public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('ImageFile', VichFileType::class,array('data_class' =>null))
        ;
    }
Argument 1 passed to App\Entity\CakePhotos::setCake() must be an instance of App\Entity\Cake or null, instance of App\Entity\Cakes given, called in /home/kumaskano1/Desktop/Learning/Symfony/Shirin/src/Entity/Cakes.php
 public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('ImageFile', VichFileType::class,array('data_class' =>null))
        ;
    }