Skip to content

Instantly share code, notes, and snippets.

@spolischook
Created February 21, 2014 18:16
Show Gist options
  • Select an option

  • Save spolischook/9139977 to your computer and use it in GitHub Desktop.

Select an option

Save spolischook/9139977 to your computer and use it in GitHub Desktop.
<?php
namespace Geekhub\DreamBundle\Controller;
use Geekhub\DreamBundle\Entity\Dream;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Application\Sonata\MediaBundle\Entity\Media;
use Sonata\MediaBundle\Entity\MediaManager;
class DefaultController extends Controller
{
public function indexAction(Request $request)
{
$files = $request->files->get('fileUpload');
$dream = new Dream();
$dream->setTitle('Blablabla');
$dream->setDescription('Blablabla');
$dream->setMainPicture('Blablabla');
$dream->setPhone('Blablabla');
$dream->setExpiredDate(new \DateTime());
$media = new Media;
$media->setBinaryContent($files->getRealPath());
$media->setProviderName('sonata.media.provider.image');
$mediaManager = $this->get('sonata.media.manager.media');
$mediaManager->save($media);
$dream->addImage($media);
$this->getDoctrine()->getManager()->persist($dream);
$this->getDoctrine()->getManager()->flush();
$files = $dream->getImages();
var_dump($files->first()->getBinaryContent()); exit;
return $this->render('GeekhubDreamBundle:Default:index.html.twig');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment