File symfony集合返回空文件
我有一张收款单File symfony集合返回空文件,file,symfony,input,collections,File,Symfony,Input,Collections,我有一张收款单 class EventType extends AbstractType { /** * {@inheritdoc} */ public function buildForm(FormBuilderInterface $builder, array $options) { $builder->add('header', TextType::class, ['attr' => ['class' => 'f
class EventType extends AbstractType
{
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('header', TextType::class, ['attr' => ['class' => 'form-control']])
->add('text', TextareaType::class, ['attr' => ['class' => 'form-control', 'rows' => '3']])
->add('fileNames', CollectionType::class, [
'mapped' => false,
'allow_add' => true,
'allow_delete' => true,
'by_reference' => false,
'label' => false,
'entry_type' => EventFileType::class,
])
->add('save', SubmitType::class, [
'label' => 'Post',
'attr' => [
'class' => 'btn btn-success',
'style' => 'margin-top: 10px;'
]
]);
}
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => Event::class,
'csrf_token_id' => 'eventToken',
'allow_extra_fields' => true,
]);
}
}
class EventFileType extends AbstractType
{
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('fileName', FileType::class);
}
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'method' => 'POST',
'csrf_token_id' => 'eventFiles',
));
}
}
这是集合的条目类型
class EventType extends AbstractType
{
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('header', TextType::class, ['attr' => ['class' => 'form-control']])
->add('text', TextareaType::class, ['attr' => ['class' => 'form-control', 'rows' => '3']])
->add('fileNames', CollectionType::class, [
'mapped' => false,
'allow_add' => true,
'allow_delete' => true,
'by_reference' => false,
'label' => false,
'entry_type' => EventFileType::class,
])
->add('save', SubmitType::class, [
'label' => 'Post',
'attr' => [
'class' => 'btn btn-success',
'style' => 'margin-top: 10px;'
]
]);
}
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => Event::class,
'csrf_token_id' => 'eventToken',
'allow_extra_fields' => true,
]);
}
}
class EventFileType extends AbstractType
{
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('fileName', FileType::class);
}
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'method' => 'POST',
'csrf_token_id' => 'eventFiles',
));
}
}
我的表格如下所示:
{{ form_start(form, {'attr': {'id': 'form_create_event'}}) }}
<ul class="tags" data-prototype="{{ form_widget(form.fileNames.vars.prototype)|e('html_attr') }}">
</ul>
{{ form_end(form) }}
所以我得到文本输入,$\u文件不是空的$form['fileNames']->getData()
将显示文件,但字段为空,因此,如果我输入两个文件:[{“fileName”:{}}},{“fileName”:{}}}]
,一个文件-[{“fileName”:{}}]
,超过3个文件显示,表单将无效。那么,我该如何让我的表单获取这些文件呢?(我不映射它们)我怎样才能得到我想要的尽可能多的文件