0

I have the following admin system setup using Sonata Admin in my SF2 project. When I click "View Image" I want to show either a popup/overlay with the image, or if it's easier, a new page with the image. The route for this is configured as /admin/ayrshireminis/gallery/galleryimage/{id}/view_image

enter image description here

I have this method in my CRUDController which the codepath enters:

/**
 * preview the image
 *
 * @return RedirectResponse
 */
public function viewImageAction()
{
    // work out which image we are approving based on the ID in the URL
    $id = $this->get('request')->get($this->admin->getIdParameter());

    $object = $this->admin->getObject($id);

    // couldn't find the object
    if (!$object) {
        throw new NotFoundHttpException(sprintf('unable to find the object with id : %s', $id));
    }

    return $this->render('SonataAdminBundle::empty_layout.html.twig', array('image' => $object));

}

How I can't find any Sonata documentation to work out howto simply display a blank page (within the Sonata Admin layout) with an image in it.

crmpicco
  • 16,605
  • 26
  • 134
  • 210

1 Answers1

1

If you want to display a blank page with an image (within the Sonata Admin layout):

// src/ACME/YourBundle/Resources/views/empty_layout.html.twig
{% extends "SonataAdminBundle::standard_layout.html.twig" %}
{% block sonata_page_content %}
<img src="{{ image.src }}" />
{% endblock %}

And in your controller:

return $this->render('ACMEYourBundle::empty_layout.html.twig', array('image' => $object));

If you just want a blank page without the admin layout, same twig template but without extending sonata admin bundle's standard layout.

devilcius
  • 1,764
  • 14
  • 18