[英]Using a custom view page for image preview in Sonata Admin in Symfony 2 project
我在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布局内)显示的问题。
如果要显示带有图像的空白页(在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));
如果只希望空白页面没有管理员布局,则使用相同的树枝模板,但不扩展Sonata Admin Bundle的标准布局。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.