Symfony2 & SonataMedia: champ actuel pas lié à un admin

J'ai été tring les derniers jours pour faire SonataMedia fonctionne avec Symfony 2.0.16... sans succès. Googler autour semble que pas beaucoup de gens utilisent ce bundle ou il y a un tutoriel ou un how-to que je ne suis pas au courant, parce que je n'obtenez pas beaucoup d'info sur les messages d'erreur que j'ai eu jusqu'à présent.

De toute façon, ma dernière tentative a donné le message d'erreur suivant:

The current field `path` is not linked to an admin. Please create one for the target entity : `` 

"chemin" est le champ utilisé pour enregistrer le fichier image (relatif) de chemin.

AttachmentAdmin.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
}

Attachment.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;
    }
}

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" ]

Merci pour l'info!

OriginalL'auteur abiyi | 2012-08-18