Последние дни я пытался заставить 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;
}
}
ГалереяHasMedia.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;
}
}
services.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" ]
Спасибо за любую информацию!