我正在尝试为SonataMediaBundle创建一个图像装置。媒体保存在数据库中并显示在管理界面中,但图像丢失。夹具和管理界面创建的记录没有区别。
以下是AppBundle\DataFixtures\ORM\LoadMediaBundleMediaData
<?php
namespace AppBundle\DataFixtures\ORM;
use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Doctrine\Common\Persistence\ObjectManager;
use Symfony\Component\HttpFoundation\File\File;
use Application\Sonata\ClassificationBundle\Entity\Context;
use Application\Sonata\ClassificationBundle\Entity\Category;
class LoadMediaBundleMediaData extends AbstractFixture implements OrderedFixtureInterface, ContainerAwareInterface
{
/**
* @var ContainerInterface
*/
private $container;
/**
* {@inheritDoc}
*/
public function load(ObjectManager $manager)
{
$context = new Context();
$context->setId('default');
$context->setName('default');
$context->setEnabled(true);
$manager->persist($context);
$manager->flush();
$category = new Category();
$category->setName('Default');
$category->setContext($context);
$category->setEnabled(true);
$manager->persist($category);
$manager->flush();
$media1File = new File(__DIR__ . '/../Assets/Images/image.jpg');
$mediaManager = $this->container->get('sonata.media.manager.media');
$media1 = $mediaManager->create();
$media1->setEnabled(true);
$media1->setBinaryContent($media1File);
$media1->setName('brunnkogel.jpg');
$media1->setContext('default');
$media1->setProviderName('sonata.media.provider.image');
$media1->setProviderStatus(1);
$mediaManager->save($media1);
$manager->persist($media1);
$manager->flush();
}
public function setContainer(ContainerInterface $container = null)
{
$this->container = $container;
}
/**
* {@inheritDoc}
*/
public function getOrder()
{
return 40;
}
}
如果我在管理界面中创建媒体,则可以正常工作,图像会保存在web/uploads/media/default/0001/01/c4412442f8f146db6acaec10751fb54e4c80e8c5.jpeg
。缩略图也在此目录中。如果我按灯具创建媒体,web/uploads/media
中的文件将丢失。
我正在使用Symfony 2.8和SonataMediaBundle 3.0。
我该如何解决这个问题?