没有奏鸣曲媒体包的列表映射器中某个实体的奏鸣曲管理包预览图像 [英] Sonata admin bundle preview image from some entity in list mapper without sonata media bundle
问题描述
我想知道我应该如何解决这个问题.在奏鸣曲管理仪表板中,我有用户,我想在 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'));}}
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屋!