如何解决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",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;
}
}
这是我的 Entity 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,$by];
}elseif(Crud::PAGE_EDIT === $pageName) {
return [$name,$by];
} elseif(Crud::PAGE_NEW === $pageName) {
return [$name,$logo,$active];
} else {
return [$name,$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');
}
}
$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".
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。