我想加載帶有圖像的DoctrineFixturesBundle的datafixtures,但我不知道如何使它工作。如何使用symfony3中的文件加載datafixtures
我這個嘗試之一:
public function load(ObjectManager $manager)
{
$imageGrabTail = new Image();
$imageGrabTail->setTrick($this->getReference('grab-tail'));
$imageGrabTail->setUpdatedAt(new \DateTimeImmutable());
$file = new UploadedFile($imageGrabTail->getUploadDir() . '/63.jpeg', 'Image1', null, null, null);
$imageGrabTail->setFile($file);
$manager->persist($imageGrabTail);
$manager->flush();
}
我的方法getUploadDir():
public function getUploadDir()
{
return 'uploads/img';
}
但我有一個錯誤:
[Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException]
The file "uploads/img/63.jpeg" does not exist
我的文件63.jpeg這個存在夾。
有沒有人可以向我解釋爲什麼它不起作用?
謝謝!
也許你在這裏解決https://stackoverflow.com/questions/12309077/how-would-you-add-a- file-upload-to-a-symfony2-datafixture使用File對象 –
魔導師;)。我已經在下午看到了這一點,我不知道爲什麼,我無法使它工作...我只是再次嘗試,現在它的工作... Thx –