我已经使用 SonataAdmin 设置了 VichUploaderBundle,我不想使用奏鸣曲对实体上传图像进行分类。
表单呈现正常,实体保存正常,发送多部分数据和图像。但它没有保存,也没有错误或调试它的东西。
配置:
vich_uploader:
db_driver: orm
mappings:
category_image:
uri_prefix: /uploads/images/category
upload_destination: %kernel.root_dir%/../web/uploads/images/category
inject_on_load: true
delete_on_remove: true
delete_on_update: true
namer: vich_uploader.namer_origname
类别管理员:
$formMapper
->add('title', 'text', ['label' => 'title'])
->add('description', 'textarea', ['required' => false, 'label' => 'description'])
->add('image', 'file',
[
'required' => false,
'label' => 'image',
'data_class' => 'Symfony\Component\HttpFoundation\File\File',
'attr' => ['class' => 'sonata-medium-file'],
]
);
类别实体:
/**
* @ORM\Column(type="string", length=255, name="image_name", nullable=true)
*/
protected $imageName;
/**
* @Assert\File(
* groups={"list"},
* maxSize="500k",
* mimeTypes={"image/png", "image/jpeg", "image/pjpeg"},
* mimeTypesMessage = "constraint.mime_type"
* )
* @Vich\UploadableField(
* mapping="category_image",
* fileNameProperty="imageName"
* )
* @var File $image
*/
protected $image;
发布:内容
Content-Disposition: form-data; name="s5519586317457[image]"; filename="ico.png"
内容类型:图片/png