最近几天我一直在努力让 SonataMedia 与 Symfony 2.0.16 一起工作……但没有成功。谷歌搜索似乎没有多少人使用该捆绑包,或者有一个我不知道的教程或操作方法,因为我没有得到太多关于我到目前为止得到的错误消息的信息。
无论如何,我最后一次尝试给出了下一条错误消息:
The current field `path` is not linked to an admin. Please create one for the target entity : ``
“路径”是用于保存文件图像(相对)路径的字段。
附件Admin.php
<?php
class AttachmentAdmin extends Admin
{
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->add(
'path',
'sonata_type_collection',
array(
'required' => true
),
array(
'edit' => 'inline',
'inline' => 'table',
'sortable' => 'position',
'targetEntity' => 'Application\Sonata\MediaBundle\Entity\GalleryHasMedia',
'link_parameters' => array(
'context' => 'attachment'
)
)
)
->add('notes', 'textarea', array('required' => false))
;
}
// other methods
}
附件.php
<?php
class Attachment
{
// other properties
/**
* @var string $path
*
* @ORM\Column(name="path", type="string", nullable=false)
* @ORM\ManyToOne(targetEntity="Application\Sonata\MediaBundle\Entity\GalleryHasMedia", cascade={"persist"})
*/
protected $path;
// other methods
/**
* Set path
*
* @param string $path
*/
public function setPath($path)
{
$this->path = $path;
foreach ($path as $ent) {
$ent->setAttachment($this);
}
}
/**
*
* @return string
*/
public function getPath()
{
return $this->path;
}
/**
*
* @param \Application\Sonata\MediaBundle\Entity\GalleryHasMedia $path
*/
public function addPath(\Application\Sonata\MediaBundle\Entity\GalleryHasMedia $path)
{
$this->path[] = $path;
}
}
GalleryHasMedia.php
<?php
class GalleryHasMedia extends BaseGalleryHasMedia
{
/**
* @var integer $id
*/
protected $id;
/**
*
* @var File
*/
private $attachment;
/**
* Get id
*
* @return integer $id
*/
public function getId()
{
return $this->id;
}
/**
*
* @param \Mercury\CargoRecognitionBundle\Entity\Attachment $attachment
* @return \Application\Sonata\MediaBundle\Entity\GalleryHasMedia
*/
public function setAttachment(\Mercury\CargoRecognitionBundle\Entity\Attachment $attachment = null)
{
$this->attachment = $attachment;
return $this;
}
/**
*
* @return \Application\Sonata\MediaBundle\Entity\File
*/
public function getAttachment()
{
return $this->attachment;
}
}
服务.yml
mercury.cargo_recognition.admin.attachment:
class: Mercury\CargoRecognitionBundle\Admin\AttachmentAdmin
tags:
- { name: sonata.admin, manager_type: orm, group: General, label: Attachments }
arguments: [ null, Mercury\CargoRecognitionBundle\Entity\Attachment, "MercuryCargoRecognitionBundle:AttachmentAdmin" ]
感谢您提供任何信息!