如何获取在sonata管理包后端列出的图像 [英] How to get images listed in sonata admin bundle backend
问题描述
这是我的imageAdmin.php
命名空间swaam\ImageUploaderBundle \Admin;
使用Sonata\AdminBundle\Admin\Admin;
使用Sonata\AdminBundle\Datagrid\ListMapper;
使用Sonata\AdminBundle\Datagrid\DatagridMapper;
使用Sonata\AdminBundle\Form\FormMapper;
class ImageAdmin extends Admin
{
//要在创建/编辑表单上显示的字段
protected function configureFormFields(FormMapper $ formMapper)
{
$ formMapper
- > add('caption','ckeditor',array('label'=>'Ca ption'))
// - > add ('file','entity',array('class'=>'swaam\ImageUploaderBundle\Entity\image'))
- > add('file','file',array 'data_class'=>'Symfony\Component\HttpFoundation\File\File'
,'property_path'=>'file'
))
- >端(); //如果没有指定类型,SonataAdminBundle尝试猜出它
;
}
//要在过滤器窗体上显示的字段
protected function configureDatagridFilters(DatagridMapper $ datagridMapper)
{
$ datagridMapper
- > add('caption')
- > add('thumbpath')
;
}
//列表上显示的字段
protected function configureListFields(ListMapper $ listMapper)
{
$ listMapper
- > ; addIdentifier('caption')
// - > add('thumbpath')
- > add('thumbpath')
;
}
}
这是我更新后的configureListFields方法
protected function configureListFields(ListMapper $ listMapper)
{
$ listMapper
// - > addIdentifier( 'caption')
// - > add('thumbpath')
// - > add('thumbpath')
- > add('thumbpath',null,array ('template'=>'swwamImageUploaderBundle:Admin:list_image.html.twig'))
// - > add('thumbpath',null,array('template'=>'swwamImageUploaderBundle:Admin: list_image.html.twig'))
;
}
这里是我的枝条
{%extends'SonataAdminBundle:CRUD:base_list_field.html.twig'%}
{%block field%}
< div>
{#< img src ={{image.webPath | imagine_filter('gallery_element_admin')}}/>#}
//< img src ={ app.request.scheme〜'://'〜app.request.host〜'/'〜image.getthumbWebPath}}/>
{#或者创建src的图像#}
< / div>
{%endblock%}
最简单方法是创建自定义管理字段模板。
在 configureListFields 方法add:
- > add('path',null ,array('template'=>'AcmeBundle:Admin:list_image.html.twig'))
并创建文件 AcmeBundle / Resources / views / Admin / list_image.html.twig 与内容:
{%extends'SonataAdminBundle:CRUD:base_list_field.html.twig'%}
{%block field%}
< div>
< img src ={{object.webPath | imagine_filter('gallery_element_admin')}}/>
{#或任何要创建的图像#src}
< / div>
{%endblock%}
I want to get my image thumbnail listed in list area, i don't know how to do that, can any one please help me. I Got my caption in back end. I am using Sonata adim bundle and following its official document.
here is my imageAdmin.php
namespace swaam\ImageUploaderBundle\Admin;
use Sonata\AdminBundle\Admin\Admin;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Form\FormMapper;
class ImageAdmin extends Admin
{
// Fields to be shown on create/edit forms
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->add('caption', 'ckeditor', array('label' => 'Ca ption'))
// ->add('file', 'entity', array('class' => 'swaam\ImageUploaderBundle\Entity\image'))
->add('file', 'file', array('data_class' => 'Symfony\Component\HttpFoundation\File\File'
,'property_path' => 'file'
))
->end(); //if no type is specified, SonataAdminBundle tries to guess it
;
}
// Fields to be shown on filter forms
protected function configureDatagridFilters(DatagridMapper $datagridMapper)
{
$datagridMapper
->add('caption')
->add('thumbpath')
;
}
// Fields to be shown on lists
protected function configureListFields(ListMapper $listMapper)
{
$listMapper
->addIdentifier('caption')
// ->add('thumbpath')
->add('thumbpath')
;
}
}
Here is my configureListFields method after updating
protected function configureListFields(ListMapper $listMapper)
{
$listMapper
// ->addIdentifier('caption')
// ->add('thumbpath')
// ->add('thumbpath')
->add('thumbpath', null, array('template' => 'swwamImageUploaderBundle:Admin:list_image.html.twig'))
// ->add('thumbpath', null, array('template' => 'swwamImageUploaderBundle:Admin:list_image.html.twig'))
;
}
and here is my twig
{% extends 'SonataAdminBundle:CRUD:base_list_field.html.twig' %}
{% block field%}
<div>
{#<img src="{{ image.webPath | imagine_filter('gallery_element_admin') }}" />#}
//<img src="{{ app.request.scheme ~ '://' ~ app.request.host ~ '/' ~ image.getthumbWebPath }}" />
{# or whatever to create src of image #}
</div>
{% endblock %}
The simplest way is to create custom admin field template. In configureListFields method add:
->add('path', null, array('template' => 'AcmeBundle:Admin:list_image.html.twig'))
And create file AcmeBundle/Resources/views/Admin/list_image.html.twig with content:
{% extends 'SonataAdminBundle:CRUD:base_list_field.html.twig' %}
{% block field%}
<div>
<img src="{{ object.webPath | imagine_filter('gallery_element_admin') }}" />
{# or whatever to create src of image #}
</div>
{% endblock %}
这篇关于如何获取在sonata管理包后端列出的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!