0

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 レイアウト内に) 画像を含む空白のページを単純に表示する方法を理解するにはどうすればよいでしょうか。

4

1 に答える 1

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));

管理レイアウトのない空白のページが必要な場合は、同じ twig テンプレートを使用しますが、sonata 管理バンドルの標準レイアウトを拡張する必要はありません。

于 2014-12-10T11:14:36.033 に答える