php - EasyAdmin 错误:“Vich\UploaderBundle\Form\Type\VichImageType”,选项“upload_dir”,“upload_filename”不存在
问题描述
对不起,我的英语很差。我需要你的帮助。
我用 symfony 5 开发了一个应用程序。我使用 EasyAdmin 3 和 VichUploader 来加载图像。这是我的 vich_uploader.yaml :
vich_uploader:
db_driver: orm
mappings:
site:
uri_prefix: '%app.path.site_images%'
upload_destination: '%kernel.project_dir%/public%app.path.site_images%'
namer: 'Vich\UploaderBundle\Naming\UniqidNamer'
这是我的实体:
<?php
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Entity\Traits\CommonFields;
use App\Repository\SiteRepository;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\HttpFoundation\File\File;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
use Vich\UploaderBundle\Mapping\Annotation\UploadableField;
/**
* @ApiResource()
* @ORM\Entity(repositoryClass=SiteRepository::class)
* @Vich\Uploadable
*/
class Site
{
use CommonFields;
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=100)
*/
private $name;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $logo;
/**
* @ORM\Column(type="string", length=100 , nullable=true)
*/
private $logoName;
/**
* @return string|null
*/
public function getLogoName()
{
return $this->logoName;
}
/**
* @param string|null $logoName
* return $this
*/
public function setLogoName($logoName)
{
$this->logoName = $logoName;
return $this;
}
/**
* @Vich\UploadableField(mapping="site" , fileNameProperty="logoName")
* @var File
*/
private $logoFile;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $promotion;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $livraison;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $remboursement;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $support;
/**
* @ORM\Column(type="text")
*/
private $about;
/**
* @ORM\Column(type="text")
*/
private $address;
/**
* @ORM\Column(type="string", length=100)
*/
private $telephone;
/**
* @ORM\Column(type="string", length=100)
*/
private $mail;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $facebook;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $twitter;
/**
* @ORM\Column(type="string", length=255)
*/
private $linkedin;
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getLogo(): ?string
{
return $this->logo;
}
public function setLogo(?string $logo): self
{
$this->logo = $logo;
return $this;
}
public function getPromotion(): ?string
{
return $this->promotion;
}
public function setPromotion(?string $promotion): self
{
$this->promotion = $promotion;
return $this;
}
public function getLivraison(): ?string
{
return $this->livraison;
}
public function setLivraison(?string $livraison): self
{
$this->livraison = $livraison;
return $this;
}
public function getRemboursement(): ?string
{
return $this->remboursement;
}
public function setRemboursement(?string $remboursement): self
{
$this->remboursement = $remboursement;
return $this;
}
public function getSupport(): ?string
{
return $this->support;
}
public function setSupport(?string $support): self
{
$this->support = $support;
return $this;
}
public function getAbout(): ?string
{
return $this->about;
}
public function setAbout(string $about): self
{
$this->about = $about;
return $this;
}
public function getAddress(): ?string
{
return $this->address;
}
public function setAddress(string $address): self
{
$this->address = $address;
return $this;
}
public function getTelephone(): ?string
{
return $this->telephone;
}
public function setTelephone(string $telephone): self
{
$this->telephone = $telephone;
return $this;
}
public function getMail(): ?string
{
return $this->mail;
}
public function setMail(string $mail): self
{
$this->mail = $mail;
return $this;
}
public function getFacebook(): ?string
{
return $this->facebook;
}
public function setFacebook(?string $facebook): self
{
$this->facebook = $facebook;
return $this;
}
public function getTwitter(): ?string
{
return $this->twitter;
}
public function setTwitter(?string $twitter): self
{
$this->twitter = $twitter;
return $this;
}
public function getLinkedin(): ?string
{
return $this->linkedin;
}
public function setLinkedin(string $linkedin): self
{
$this->linkedin = $linkedin;
return $this;
}
/**
* @param File|null $logo
*/
public function setLogoFile(?File $logoFile = null)
{
$this->logoFile = $logoFile;
$this->logo = base64_encode($logoFile);
}
/**
* @return File|null
*/
public function getLogoFile(): ?File
{
return $this->logoFile;
}
}
这是我的实体 Crud:
<?php
namespace App\Controller\Admin;
use App\Entity\Site;
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
use EasyCorp\Bundle\EasyAdminBundle\Field\BooleanField;
use EasyCorp\Bundle\EasyAdminBundle\Field\DateTimeField;
use EasyCorp\Bundle\EasyAdminBundle\Field\EmailField;
use EasyCorp\Bundle\EasyAdminBundle\Field\ImageField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TelephoneField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextEditorField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use EasyCorp\Bundle\EasyAdminBundle\Field\UrlField;
use Vich\UploaderBundle\Form\Type\VichImageType;
class SiteCrudController extends AbstractCrudController
{
public static function getEntityFqcn(): string
{
return Site::class;
}
public function configureFields(string $pageName): iterable
{
$name = TextField::new('name');
$logo = ImageField::new('logoFile','Logo')
->setBasePath("/images/site")
->setUploadDir("public/images/site")
->setFormType(VichImageType::class)
;
$promotion = TextEditorField::new('promotion');
$livraison = TextEditorField::new('livraison');
$remboursement = TextEditorField::new('remboursement');
$support = TextEditorField::new('support');
$about = TextEditorField::new('about');
$address = TextEditorField::new('address');
$telephone = TelephoneField::new('telephone');
$mail = EmailField::new('mail');
$facebook = UrlField::new('facebook');
$twitter = UrlField::new('twitter');
$linkedin = UrlField::new('linkedin');
$created = DateTimeField::new('createdAt');
$update = DateTimeField::new('updatedAt');
$active = BooleanField::new('isActived');
$delete = BooleanField::new('isDeleted');
$by = TextField::new('createdBy');
if (Crud::PAGE_INDEX === $pageName) {
return [$name, $promotion, $livraison, $remboursement, $support, $about, $address, $telephone, $mail, $facebook, $twitter, $linkedin, $created, $update, $active, $by];
} elseif(Crud::PAGE_DETAIL === $pageName) {
return [$name, $promotion, $livraison, $remboursement, $support, $about, $address, $telephone, $mail, $facebook, $twitter, $linkedin, $created, $update, $active, $by];
}elseif(Crud::PAGE_EDIT === $pageName) {
return [$name, $promotion, $livraison, $remboursement, $support, $about, $address, $telephone, $mail, $facebook, $twitter, $linkedin, $created, $update, $active, $by];
} elseif(Crud::PAGE_NEW === $pageName) {
return [$name,$logo, $promotion, $livraison, $remboursement, $support, $about, $address, $telephone, $mail, $facebook, $twitter, $linkedin, $active];
} else {
return [$name, $promotion, $livraison, $remboursement, $support, $about, $address, $telephone, $mail, $facebook, $twitter, $linkedin, $created, $update, $active, $by];
}
// return [
// TextField::new('name'),
// TextEditorField::new('description'),
// BooleanField::new('isActived'),
// ];
}
public function configureCrud(Crud $crud): Crud
{
return $crud
->setEntityLabelInSingular('Paramètre')
->setEntityLabelInPlural('Paramètres')
->setPageTitle('index', '%entity_label_plural%')
->setPageTitle('new', 'Ajouter les paramètres du site')
->setPageTitle('detail', 'Paramètre du site')
->setPageTitle('edit', 'Modifier les paramètres du site')
->setHelp('edit', 'Vous modifez les paramètres du site');
}
}
我的 configureFields 函数出错
$logo = ImageField::new('logoFile','Logo')
->setBasePath("/images/site")
->setUploadDir("public/images/site")
->setFormType(VichImageType::class)
;
我犯了这个错误:
An error has occurred resolving the options of the form "Vich\UploaderBundle\Form\Type\VichImageType": The options "upload_dir", "upload_filename" do not exist. Defined options are: "action", "allow_delete", "allow_extra_fields", "allow_file_upload", "asset_helper", "attr", "attr_translation_parameters", "auto_initialize", "block_name", "block_prefix", "by_reference", "compound", "constraints", "csrf_field_name", "csrf_message", "csrf_protection", "csrf_token_id", "csrf_token_manager", "data", "data_class", "delete_label", "disabled", "download_label", "download_link", "download_uri", "ea_crud_form", "empty_data", "error_bubbling", "error_mapping", "extra_fields_message", "getter", "help", "help_attr", "help_html", "help_translation_parameters", "image_uri", "imagine_pattern", "inherit_data", "invalid_message", "invalid_message_parameters", "is_empty_callback", "label", "label_attr", "label_format", "label_html", "label_translation_parameters", "legacy_error_messages", "mapped", "method", "post_max_size_message", "property_path", "required", "row_attr", "setter", "storage_resolve_method", "translation_domain", "trim", "upload_max_size_message", "validation_groups".
解决方案
推荐阅读
- parallel-processing - 从一个巨大的文件中并行使用 grep 模式并将每个模式打印到一个新文件中
- c# - 使用 nunit3-console.exe 在 Jenkins 主服务器上进行 Selenium IE 11 测试
- android - 单击时更改我的 ToggleButton 的颜色
- regex - 贪婪的Python正则表达式问题
- r - R写一个函数输入等于整数,但输入可能是NA
- powershell - SCCM WQL 查询 - 特定已安装应用程序的列表版本?
- mongodb - 在mongo查询中从数组中获取数据
- c++ - 当 A 和 B “相同”时断言 (sizeof(A) == sizeof(B)) 是否安全?
- python - 大熊猫在行之间移动增量
- c# - Typewriter 生成的 TS 文件不是模块