简体   繁体   English

在Symfony 2项目的Sonata Admin中使用自定义视图页面进行图像预览

[英]Using a custom view page for image preview in Sonata Admin in Symfony 2 project

I have the following admin system setup using Sonata Admin in my SF2 project. 我在SF2项目中使用Sonata Admin进行了以下管理系统设置。 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 为此的路由配置为/admin/ayrshireminis/gallery/galleryimage/{id}/view_image

在此处输入图片说明

I have this method in my CRUDController which the codepath enters: 我在代码路径输入的CRUDController中有此方法:

/**
 * 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. 我如何找不到任何Sonata文档来解决如何简单地在其中包含图像的空白页面(在Sonata Admin布局内)显示的问题。

If you want to display a blank page with an image (within the Sonata Admin layout): 如果要显示带有图像的空白页(在Sonata Admin布局内):

// 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. 如果只希望空白页面没有管理员布局,则使用相同的树枝模板,但不扩展Sonata Admin Bundle的标准布局。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM