我想用VichUploaderBundle上传文件。有我的实体
........
/**
*
* @Vich\UploadableField(mapping="product_image", fileNameProperty="imageName")
*
* @var File $imageFile
*/
protected $imageFile;
/**
* @ORM\Column(type="string", length=255, name="image_name")
*
* @var string $imageName
*/
protected $imageName;
/**
* @ORM\Column(type="datetime")
*
* @var \DateTime $updatedAt
*/
protected $updatedAt;
/**
* @param File|\Symfony\Component\HttpFoundation\File\UploadedFile $image
*/
public function setImageFile(File $image = null)
{
$this->imageFile = $image;
if ($image) {
$this->updatedAt = new \DateTime('now');
}
}
/**
* @return File
*/
public function getImageFile()
{
return $this->imageFile;
}
/**
* @param string $imageName
*/
public function setImageName($imageName)
{
$this->imageName = $imageName;
}
/**
* @return string
*/
public function getImageName()
{
return $this->imageName;
}
.........
我的表单构建器看起来像
........
$builder
->add('brand')
->add('model')
->add('price')
->add('imageName')
->add('updatedAt')
->add('sub_rel')
.......
我的配置文件看起来像
vich_uploader:
db_driver: orm
mappings:
product_image:
uri_prefix: /images/goods
upload_destination: %kernel.root_dir%/../web/images/goods
inject_on_load: false
delete_on_update: true
delete_on_remove: true
问题: 我需要更改什么才能使用此捆绑包下载几张图片?
答案 0 :(得分:0)
您的表单应如下所示:
<img src="{{ vich_uploader_asset(product, 'image') }}" alt="{{ product.name }}" />
如果您想要展示产品,请在您的前端:
string[] myArray = new string[5];
捆绑文档中记录了所有内容:https://github.com/dustin10/VichUploaderBundle/blob/master/Resources/doc/index.md
我建议使用LiipImagineBundle为你的前端/后端生成所有需要的缩略图。