我想在我的数据库中上传和存储两个文件:文档和文档封面图片。但只有文件列。第二张图片不在里面。
这就是我的实体类的样子:
class Document
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="document_title", type="string", length=255)
*/
private $documentTitle;
/**
* @ORM\Column(type="string", length=255)
* @var string
*/
private $fileName;
/**
*@Vich\UploadableField(mapping="user_documents", fileNameProperty="fileName")
* @var File
*/
private $documentFile;
/*
* @ORM\Column(type="string", length=255)
* @var string
*/
private $coverName;
/**
*@Vich\UploadableField(mapping="documents_covers", fileNameProperty="coverName")
* @var File
*/
private $documentCover;
/**
* @ORM\ManyToOne(targetEntity="Foo\UserBundle\Entity\User", inversedBy="documents")
**/
private $owner;
}
这是我的二传手的样子:
public function setDocumentFile(File $documentFile = null)
{
$this->documentFile = $documentFile;
if ($documentFile){
$this->updatedAt = new \DateTime('now');
}
return $this;
}
/**
* @param File $documentCover
*/
public function setDocumentCover(File $documentCover = null)
{
$this->documentCover = $documentCover;
}
还有我的 vich 上传器配置:
vich_uploader:
db_driver: orm
storage: file_system
mappings:
documents_covers:
uri_prefix: %app.path.documents_covers%
upload_destination: %kernel.root_dir%/../web/uploads/images/documents
namer: vich_uploader.namer_uniqid
user_documents:
uri_prefix: %app.path.user_documents%
upload_destination: %kernel.root_dir%/../web/uploads/files/user/documents
namer: vich_uploader.namer_uniqid
当我查看那里的目录时,文件存在那里,但是当我查看 DB 时,只有 $documentFile。 文档表数据