【发布时间】:2020-03-01 06:16:24
【问题描述】:
我在 Symfony 3.4 中有一个这样的表单集合:
// MainType.php
$builder->add('children', CollectionType::class, ['entry_type' => ChildType::class]);
// ChildType.php
$builder->add('myField', null, ['mapped' => false]);
// plus more fields, mapped to the underlying `Child` entity
// Controller
$form = $this->createForm(MainType::class, ['children' => $children]);
$form->handleRequest($request);
if ($form->isSubmitted() and $form->isValid()) {
// How can I access the data of `myField` here?
}
当用通常的方式做时
$data = $form->getData();
...我得到的是 Child 实体的数组,而不是表单本身。
所以换句话说,问题是:在表单集合中,我如何访问子 forms,而不是子 entities?
【问题讨论】: