0

I have a Product entity mapped as follow:

class Product
{

    use IdentifiedAutogeneratedEntityTrait;
    use BaseEntityTrait;

    ......

    /**
     * @ORM\ManyToOne(targetEntity="\Application\Sonata\MediaBundle\Entity\Media")
     * @ORM\JoinColumn(name="product_image", referencedColumnName="id")
     */
    protected $image;

   ......

    public function setImage(\Application\Sonata\MediaBundle\Entity\Media $image)
    {
        $this->image = $image;
    }
}

Then in my admin form I have this:

protected function configureFormFields(FormMapper $form)
{
    $form
            ->add('product_name', null)
            ->add('product_description', null)
            ->add('image', 'sonata_type_admin');
}

When I add a new product I can upload a image and yes it works but I can see the image on the page where I'm creating the product, how I can do that?

ReynierPM
  • 17,594
  • 53
  • 193
  • 363
  • 1
    I guess this should do the job for you [**`MEDIABUNDLE ~ MEDIATYPE IMPROVED`**](http://sonata-project.org/blog/2013/10/11/mediabundle-mediatype-improved) – M Khalid Junaid Aug 13 '14 at 20:02

1 Answers1

0

I think you have to use sonata_type_model_list and not sonata_type_admin.

protected function configureFormFields(FormMapper $form)
{
    $form
            ->add('product_name', null)
            ->add('product_description', null)
            ->add('image', 'sonata_type_model_list');
}
Etienne Noël
  • 5,988
  • 6
  • 48
  • 75