[英]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.