我希望你能帮助我,因为我正在寻找,但我迷路了:(
我正在尝试使用 VichUploaderBundle 在我的 symfony 6 项目中上传图像。
但我有这个错误:
类“App\Entity\Client”不可上传。
@Vich\Uploadable如果您使用注释来配置 VichUploaderBundle,您可能只是忘记在实体之上添加。如果您不使用注释,请检查配置文件是否位于正确的位置。在这两种情况下,清除缓存也可以解决问题。
我的 vich_uploader.yaml :
vich_uploader:
db_driver: orm
mappings:
clients_logo:
uri_prefix: '%client_logo%'
upload_destination: '%kernel.project_dir%/public%client_logo%'
namer: Vich\UploaderBundle\Naming\SmartUniqueNamer
Run Code Online (Sandbox Code Playgroud)
我的客户实体:
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use App\Repository\ClientRepository;
use Doctrine\Common\Collections\Collection;
use Symfony\Component\HttpFoundation\File\File;
use Doctrine\Common\Collections\ArrayCollection;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
#[ORM\Entity(repositoryClass: ClientRepository::class)]
#[Vich\Uploadable]
class Client
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private $id;
#[ORM\Column(type: 'integer')]
private $numero_client;
/**
* Some fields
*/
/**
* NOTE: This is not a mapped field of entity …Run Code Online (Sandbox Code Playgroud)