没有奏鸣曲媒体包的列表映射器中某个实体的奏鸣曲管理包预览图像 [英] Sonata admin bundle preview image from some entity in list mapper without sonata media bundle

查看:27
本文介绍了没有奏鸣曲媒体包的列表映射器中某个实体的奏鸣曲管理包预览图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道我应该如何解决这个问题.在奏鸣曲管理仪表板中,我有用户,我想在 ListMapper 的缩略图中预览用户个人资料图片.我是 symfony 的新手,在试图围绕这些概念进行思考时仍然有点困惑.

解决方案

您需要创建一个自定义模板来显示您的用户的图像,我将假设您的实体用户作为具有路径方法的图片实体给出图片网址:

picture.html.twig

{% 扩展 'SonataAdminBundle:CRUD:base_list_field.html.twig' %}{% 块字段 %}<div>{% if object.picture != null %}<img src="{{ object.picture.path }}">{% 别的 %}<span>无图片</span>{% 万一 %}

{% 结束块 %}

您知道必须在列表中使用此模板

class UserAdmin 扩展了 Admin{受保护的函数 configureListFields(ListMapper $listMapper){$listMapper->addIdentifier('id')->add('图片', null, 数组('模板' =>'ApplicationSonataAdminBundle:User:picture.html.twig'));}}

文档在此处可用:http://Sonata-project.org/bundles/doctrine-orm-admin/master/doc/reference/list_field_definition.html#custom-template

I was wondering how should i approach this problem. In sonata admin dashboard i have users and i would like to preview users profile pictures in thumbnails of a ListMapper. I'm new to symfony and still a bit confused trying to wrap my head around these concepts.

解决方案

You need to create a custom template where you display the image of your user, i will assume that your Entity User as a Picture Entity which has a path method that gives the image URL :

picture.html.twig

{% extends 'SonataAdminBundle:CRUD:base_list_field.html.twig' %}
{% block field %}
<div>
    {% if object.picture != null %}
    <img src="{{ object.picture.path }}">
    {% else %}
    <span>No picture</span>
    {% endif %}
</div>
{% endblock %}

You know have to use this template in your list

class UserAdmin extends Admin
{
    protected function configureListFields(ListMapper $listMapper)
    {
        $listMapper
            ->addIdentifier('id')
            ->add('picture', null, array(
                'template' => 'ApplicationSonataAdminBundle:User:picture.html.twig'
            ));
    }
}

Documentation is available here : http://sonata-project.org/bundles/doctrine-orm-admin/master/doc/reference/list_field_definition.html#custom-template

这篇关于没有奏鸣曲媒体包的列表映射器中某个实体的奏鸣曲管理包预览图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆