Note that there are some explanatory texts on larger screens.

plurals
  1. POSymfony2 & SonataMedia: current field not linked to an admin
    primarykey
    data
    text
    <p>I've been tring the last days to make SonataMedia works with Symfony 2.0.16... with no success. Googling around seems like no much people use that bundle or there's a tutorial or an how-to that I'm not aware of, cause I don't get to much info about the error messages I've got so far.</p> <p>Anyway, my last attempt gave the next error message: </p> <pre><code>The current field `path` is not linked to an admin. Please create one for the target entity : `` </code></pre> <p>"path" is the field used to save the file image (relative) path.</p> <p><strong>AttachmentAdmin.php</strong></p> <pre><code>&lt;?php class AttachmentAdmin extends Admin { protected function configureFormFields(FormMapper $formMapper) { $formMapper -&gt;add( 'path', 'sonata_type_collection', array( 'required' =&gt; true ), array( 'edit' =&gt; 'inline', 'inline' =&gt; 'table', 'sortable' =&gt; 'position', 'targetEntity' =&gt; 'Application\Sonata\MediaBundle\Entity\GalleryHasMedia', 'link_parameters' =&gt; array( 'context' =&gt; 'attachment' ) ) ) -&gt;add('notes', 'textarea', array('required' =&gt; false)) ; } // other methods } </code></pre> <p><strong>Attachment.php</strong></p> <pre><code>&lt;?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-&gt;path = $path; foreach ($path as $ent) { $ent-&gt;setAttachment($this); } } /** * * @return string */ public function getPath() { return $this-&gt;path; } /** * * @param \Application\Sonata\MediaBundle\Entity\GalleryHasMedia $path */ public function addPath(\Application\Sonata\MediaBundle\Entity\GalleryHasMedia $path) { $this-&gt;path[] = $path; } } </code></pre> <p><strong>GalleryHasMedia.php</strong></p> <pre><code>&lt;?php class GalleryHasMedia extends BaseGalleryHasMedia { /** * @var integer $id */ protected $id; /** * * @var File */ private $attachment; /** * Get id * * @return integer $id */ public function getId() { return $this-&gt;id; } /** * * @param \Mercury\CargoRecognitionBundle\Entity\Attachment $attachment * @return \Application\Sonata\MediaBundle\Entity\GalleryHasMedia */ public function setAttachment(\Mercury\CargoRecognitionBundle\Entity\Attachment $attachment = null) { $this-&gt;attachment = $attachment; return $this; } /** * * @return \Application\Sonata\MediaBundle\Entity\File */ public function getAttachment() { return $this-&gt;attachment; } } </code></pre> <p><strong>services.yml</strong></p> <pre><code> 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" ] </code></pre> <p>Thanks for any info!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload