小编MrF*_*rid的帖子

Symfony 3 上使用 VichUploaderBundle 进行“多重上传”

我尝试允许使用捆绑包 VichUploader 进行多次上传。在该项目中,我有一个类剧院,它拥有一个主图像,但也有一些辅助图像(图像集合)。实际上,每个辅助图像都是一个资源。\n因此,一个剧院有一个多个资源,一个资源连接到一个剧院。

\n\n

但是当我尝试创建时,我可以访问我的表单,但当我尝试保存时出现错误:

\n\n
Expected argument of type "AppBundle\\Entity\\Resources", "AppBundle\\Entity\\Theatre" given \n
Run Code Online (Sandbox Code Playgroud)\n\n

这是我的班级剧院,仅包含多次上传的详细信息:

\n\n
namespace AppBundle\\Entity;\n\nuse Doctrine\\Common\\Collections\\ArrayCollection;\nuse Doctrine\\ORM\\Mapping as ORM;\nuse Symfony\\Component\\HttpFoundation\\File\\File;\nuse Symfony\\Component\\HttpFoundation\\File\\UploadedFile;\nuse Symfony\\Component\\Validator\\Constraints as Assert;\nuse Symfony\\Component\\Validator\\Context\\ExecutionContextInterface;\nuse Vich\\UploaderBundle\\Mapping\\Annotation as Vich;\n\n/**\n* Theatre\n*\n* @ORM\\Table(name="theatre")\n* @ORM\\Entity\n* @Vich\\Uploadable\n*/\nclass Theatre\n{\n\n/**\n *  @var ArrayCollection\n * @ORM\\OneToMany(targetEntity="Resources", mappedBy="theatre", cascade={"persist", "remove"}, orphanRemoval=true)\n */\nprivate $images;\n\n// ..\n\n/**\n * Constructor\n */\npublic function __construct()\n{\n    $this->images = new \\Doctrine\\Common\\Collections\\ArrayCollection();\n}\n\n// MultiUpload\n/**\n * @return ArrayCollection\n */\npublic function getImages()\n{\n    return $this->images;\n}\n\n/**\n * @param ArrayCollection $pictures\n */\npublic function setImages($pictures)\n{\n    $this->images = $pictures;\n}\n\npublic function getAttachImages()\n{\n    return …
Run Code Online (Sandbox Code Playgroud)

file-upload symfony vichuploaderbundle symfony-3.4

2
推荐指数
1
解决办法
8514
查看次数