如何显示SonataAdminBundle中上传字段上方的当前图片? [英] How to display the current picture above the upload field in SonataAdminBundle?
问题描述
我正在使用 SonataAdminBundle (使用Doctrine2 ORM),并且已经成功地将文件上传功能添加到了我的图片模型中。
就像在 Show 和 Edit 页面中显示简单的< img src ={{picture.url}} alt ={ {picture.title}} />
标签就在相关的表单字段上方(当然,被编辑的图片当然不是新的),以便用户可以看到当前的照片,是否改变它。
经过数小时的研究,我一直无法弄清楚如何去做。我想我需要重写一些模板,但我有点失落...
有人可以给我一个提示吗?
谢谢! 以下是我的PictureAdmin类的相关部分。 您可以通过 对象,所以你可以调用get方法和拉图像路径 要以编辑模式显示图片,您必须覆盖 还有一些包含这种功能的包 I am using SonataAdminBundle (with Doctrine2 ORM) and I have successfully added a file upload feature to my Picture model. I would like, on the Show and Edit pages, to display a simple After hours of research, I've been unable to figure out how to do it. I suppose I need to override some template, but I'm a bit lost...
Can somebody give me a hint? Thank you! Here is the relevant section of my PictureAdmin class.
You can easily do this on show page
by template attribute pass on and inside your template you get current object so u can call get method and pull image path To show image in edit mode you have to override There is also some bundle which is having this kind of functionality
check out this GenemuFormBundle 这篇关于如何显示SonataAdminBundle中上传字段上方的当前图片?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
$ b
protected function configureFormFields(FormMapper $ formMapper)
{
$ formMapper
- > add ('category',NULL,['label'=>'Catégorie'])
- > add('title',NULL,['label'=>'Titre'])
- > add('file','file',['required'=> false,'label'=>'Fichier'])//在此字段附近添加图片
- > add ('''''''','''''''',''''''), >'Visible'])
- > add('position',NULL,['label'=&'Position']);
保护函数configureShowFields(ShowMapper $ showMapper)
{
$ showMapper
- > add('id',NULL,['label '=>'ID'])
- > add('category',NULL,['label'=>'Catégorie'])
- > add('title',NULL ['label'=>'Titre'])
- > add('slug',NULL,['label'=>'Titre(URL)'])
- > add('creation_date',NULL,['label'=>'Date d \'ajout'])
- > add('visible',NULL,['label'=&''Visible' ])
- > add('position',NULL,['label'=&''Position']);
//在某处添加图片
}
$ showmapper
$ $ $ $ $ $ $'$'$&'; $'$&';项目:mytemplate.html.twig'
);
{%block name%} {{admin.trans (field_description.label)}} {%endblock%}< / th>
< td>
< img src ={{object.getFile}}title ={{object。 getTitle}}/>
< / br>
{%block field%} {{value | nl2br}} {%endblock%}
< / td>
fileType
或者您必须在 fileType
之上创建自己的customType
请看这个 GenemuFormBundle <img src="{{ picture.url }} alt="{{ picture.title }} />
tag just above the relevant form field (provided that the Picture being edited is not new, of course), so that the user may see the current photo, and decide whether to change it or not.protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->add('category', NULL, ['label' => 'Catégorie'])
->add('title', NULL, ['label' => 'Titre'])
->add('file', 'file', ['required' => false, 'label' => 'Fichier']) // Add picture near this field
->add('creation_date', NULL, ['label' => 'Date d\'ajout'])
->add('visible', NULL, ['required' => false, 'label' => 'Visible'])
->add('position', NULL, ['label' => 'Position']);
}
protected function configureShowFields(ShowMapper $showMapper)
{
$showMapper
->add('id', NULL, ['label' => 'ID'])
->add('category', NULL, ['label' => 'Catégorie'])
->add('title', NULL, ['label' => 'Titre'])
->add('slug', NULL, ['label' => 'Titre (URL)'])
->add('creation_date', NULL, ['label' => 'Date d\'ajout'])
->add('visible', NULL, ['label' => 'Visible'])
->add('position', NULL, ['label' => 'Position']);
// Add picture somewhere
}
$showmapper
->add('picture', NULL, array(
'template' => 'MyProjectBundle:Project:mytemplate.html.twig'
);
<th>{% block name %}{{ admin.trans(field_description.label) }}{% endblock %}</th>
<td>
<img src="{{ object.getFile }}" title="{{ object.getTitle }}" />
</br>
{% block field %}{{ value|nl2br }}{% endblock %}
</td>
fileType
or you have to create your own customType on top of fileType
登录
关闭