Symfony2 upload image to PHPCR

205 views Asked by At

I have DoctrinePHPCR and the MediaBundle installed on Symfony so that I may upload an image.

The main example http://symfony.com/doc/master/cmf/book/database_layer.html Only describes how to save a "Document" in a Default Controller. I already have a Doctrine entity set up with an elaborate form attached, how can I persist an ImageInterface object from the MediaBundle to PHPCR within a Docrine Entity?

I could make a connection from scratch, but that would defeat the purpose of setting up my YAML configuration files with all the connection details.

This will fail, i don't seem to have access to Symfony's "get" $this->get('doctrine_phpcr')->getManager();

This is what my entity looks like.

<?php

namespace AppBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Symfony\Cmf\Bundle\MediaBundle\ImageInterface as ImageInterface;

/**
 * Cookie
 *
 * @ORM\Table()
 * @ORM\Entity(repositoryClass="AppBundle\Entity\CookieRepository")
 */
class Cookie
{

    /**
    * @var integer
    *
    * @ORM\Column(name="id", type="integer")
    * @ORM\Id
    * @ORM\GeneratedValue(strategy="AUTO")
    */
    private $id;

    /**
    * @var string
    *
    * @ORM\Column(name="image_url", type="string", length=2047)
    */
    private $imageUrl;

    /**
     * Set imageUrl
     *
     * @param ImageInterface $imageUrl
     * @return Cookie
     */
    public function setImageUrl( $imageUrl)
    {
        $this->get('doctrine_phpcr')->getManager();
        // The previous line will fail.
        $this->imageUrl = $imageUrl;

        return $this;
    }

    /**
     * Get imageUrl
     *
     * @return ImageInterface
     */
    public function getImageUrl()
    {
        return $this->imageUrl;
    }
}
0

There are 0 answers