我有一个简单的形式与索纳塔管理员.
我希望用户可以添加一个整数列表(尽可能多).之后它将作为数组存储在我的对象中:
[1,2,3,6,9]
有没有办法在不创建另一个类来实例化整数的情况下呢?
更新:
我知道如何关闭的唯一方法是使用如下选择:
->add('type', 'choice', [
"required" => true,
"expanded" => true,
"multiple" => false,
"choices" => Campanha::getTypes(),
])
但是由于我的选择数量有限,我希望用户可以自由添加数量和他想要的值
解决方法:
尝试查看sonata_type_native_collection:
This bundle handle the native Symfony collection form type by adding:
- an add button if you set the allow_add option to true.
- a delete button if you set the allow_delete option to true.
而Symfony collection form type:
This field type is used to render a “collection” of some field or form. In the easiest sense, it could be an array of TextType fields that populate an array emails values.
所以,对于你的情况,可能是这样的:
->add('type', 'sonata_type_native_collection', [
'required' => true,
'entry_type' => 'number',
'options' => [
// Any options you'd like the integer fields to have.
]
])
(当然,这根本不能说明您需要对基础模型做出的改变.)
编辑:根据@Matheus Oliveira的评论,将’entry_options’数组键更改为’options’.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。