Q
Q
Qixing2015-03-22 09:21:42
symfony
Qixing, 2015-03-22 09:21:42

How to add images to Sonata Admin?

There are two entities:

  • Item - products {id, name}
  • ItemImage - product images {id,url,itemId}

As in sonata admin based on the above entities. For how is https://sonata-project.org/bundles/admin/master/do... extremely inconvenient.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Pavlov, 2015-03-22
@Qixing

I am using VichUploaderBundle to save images to an entity. It turns out quite convenient (I don’t like the fact that you can’t directly display item.picture in twig, but you have to display it through vich_uploader_asset(item, 'image')).
And in the admin panel, I display the thumbnail of the picture through the help

$helper = $this->getConfigurationPool()->getContainer()->get('vich_uploader.templating.helper.uploader_helper');
$src = $helper->asset($this->getSubject(), 'image');
$formMapper->setHelps([
    'picture' => "<img src=\"$src\" width=\"100\">",
]);

But I use this if the picture needs to be added to the visitor, and if I add it myself in the admin panel, then I use it using FMEfinderBundle.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question