[英]simple_array handling with SonataAdminBundle
My entity has a property from type simple_array
, storing a list of strings which are generated by the user (so choice
does not apply). 我的实体有一个类型为simple_array
的属性,存储由用户生成的字符串列表(因此choice
不适用)。
The relevant part from the entity: 实体的相关部分:
/**
* @var array
*
* @ORM\Column(type="simple_array")
*/
private $tags;
I would like to use the SonataAdminBundle to show, create and edit the entity with the tags present: 我想使用SonataAdminBundle显示,创建和编辑存在标签的实体:
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->add('tags', 'collection');
}
protected function configureListFields(ListMapper $listMapper)
{
$listMapper
->add('tags', 'array');
}
The list works, but shows [0 => Tag1, 1 => Tag2]
where I'd rather show Tag1, Tag2
. 该列表有效,但显示[0 => Tag1, 1 => Tag2]
,我宁愿显示Tag1, Tag2
。 The create and edit does not work at all, showing nothing where the input field for the tags should be. 创建和编辑根本不起作用,不显示标记的输入字段应该是什么。
To be clear: Tags are not a related entity, they are simply an array of strings! 要明确:标签不是一个相关的实体,它们只是一个字符串数组!
For add/edit your tags I recommend this general solution How to add an array (customisable) to a symfony2 form (with sonata Admin)? 为了添加/编辑你的标签,我推荐这个通用解决方案如何将数组(可自定义)添加到symfony2表单(带奏鸣曲管理员)?
For customization of array values (by defaults) in list mode as you need, just overwrites the list_array.html.twig
template from SonataAdminBundle, to something like this: 要根据需要自定义列表模式中的数组值(默认情况下),只需将list_array.html.twig
模板覆盖为以下内容:
{% extends admin.getTemplate('base_list_field') %}
{% block field %}
{{ value|join(', ') }}
{% endblock %}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.