我在 Symfony 上安装了 DoctrinePHPCR 和 MediaBundle,以便我可以上传图像。
主要示例http://symfony.com/doc/master/cmf/book/database_layer.html 仅描述了如何在默认控制器中保存“文档”。我已经设置了一个附有详细表单的 Doctrine 实体,如何将一个 ImageInterface 对象从 MediaBundle 持久化到 Docrine 实体中的 PHPCR?
我可以从头开始建立连接,但这会破坏设置包含所有连接详细信息的 YAML 配置文件的目的。
这将失败,我似乎无法访问 Symfony 的“获取”
$this->get('doctrine_phpcr')->getManager();
这就是我的实体的样子。
<?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;
}
}