我有一个ColletionType
的{{1}}表格,每个表格都用于编辑Alert实体的文本内容。我快要解决了,但是提交一个警报的EditType
会提交其余的,而EditType
会作为内容传递。
collectiontype表单类型
null
嵌入式表单类型
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('alerts', CollectionType::class,
[
'entry_type' => EditAlertType::class,
'entry_options' => ['label' => false],
]);
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => AlertManager::class
]);
}
控制器代码
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('content', TextType::class, ['required' => true]);
$builder
->add('edit', SubmitType::class,
array
(
'label' => 'Save changes',
'attr' => ['class' => 'btn btn-primary']
))
;
}
public function configureOptions (OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => Alert::class
]);
}