Created
August 28, 2011 02:00
-
-
Save iampersistent/1176142 to your computer and use it in GitHub Desktop.
using SonataMediaBundle w/o SonataAdminBundle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// in controller ... | |
$mgr = $this->get('sonata.media.manager.media'); | |
$pool = $this->get('sonata.media.pool'); | |
$class = $mgr->getClass(); | |
$medium = new $class(); | |
$medium->setProviderName('sonata.media.provider.image'); | |
$form = $this->createForm(new MediaFormType(), $medium); | |
if ($this->getRequest()->getMethod() === 'POST') { | |
$form->bindRequest($this->getRequest()); | |
if ($form->isValid()) { | |
$pool->prePersist($medium); | |
$mgr->update($medium); | |
$pool->postPersist($medium); // includes generate thumbnails | |
$this->redirect($this->generateUrl('picture')); | |
} | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The bundle needs to be updated to use the current forms in SF2, for now, build your own. | |
use Symfony\Component\Form\AbstractType; | |
use Symfony\Component\Form\FormBuilder; | |
class MediaFormType extends AbstractType | |
{ | |
public function buildForm(FormBuilder $builder, array $options) | |
{ | |
$builder | |
->add('binaryContent', 'file'); | |
} | |
public function getName() | |
{ | |
return 'sonata_media'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment