【问题标题】:Using a custom view page for image preview in Sonata Admin in Symfony 2 project在 Symfony 2 项目的 Sonata Admin 中使用自定义视图页面进行图像预览
【发布时间】:2023-03-08 01:27:01
【问题描述】:

我在我的 SF2 项目中使用 Sonata Admin 进行了以下管理系统设置。当我单击“查看图像”时,我想显示带有图像的弹出窗口/叠加层,或者如果更简单,则显示带有图像的新页面。这个路由配置为/admin/ayrshireminis/gallery/galleryimage/{id}/view_image

我在代码路径输入的 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));

}

我怎么找不到任何 Sonata 文档来解决如何简单地显示一个包含图像的空白页面(在 Sonata Admin 布局中)。

【问题讨论】:

    标签: php symfony php-5.3 sonata-admin sonata


    【解决方案1】:

    如果您想显示带有图像的空白页面(在 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 %}
    

    在你的控制器中:

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

    如果你只想要一个没有管理布局的空白页面,相同的树枝模板但没有扩展奏鸣曲管理包的标准布局。

    【讨论】:

      猜你喜欢
      • 2012-11-16
      • 2019-03-28
      • 1970-01-01
      • 2016-12-18
      • 2013-11-25
      • 2023-04-01
      • 2013-12-19
      • 1970-01-01
      • 2015-05-15
      相关资源
      最近更新 更多