我有一个与 ArticleOrder 实体有 OneToMany 关系的 PurchaseOrder 实体。此外,ArticleOrder 实体不仅包含 Order 和 Article ID ,还包含 Amount。此外,ArticleOrder 实体与另一个名为 ArticleSupplier 的实体具有 OneToMany 关系。这样每篇文章的订购金额可以拆分给多个供应商。现在我想建立一个表格来解决这个问题。所以我创建了三种表单类型:
一个只包含 ArticleOrders 的嵌入式集合:
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('purchaseOrders', 'collection', array('type' => new ProducedAmountOrderArticleType()));
}
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'Acme\AppBundle\Entity\PurchaseOrder',
));
}
一个包含 ArticleSupplier 条目的嵌入式集合:
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('articleOrderReferences', 'collection', array('type' => new ProducedAmountOrderSubArticleType()));
}
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'Acme\AppBundle\Entity\ArticleOrderReference',
));
}
还有一个用于 ArticleSupplier Amount 输入字段:
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('produced');
}
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'Acme\AppBundle\Entity\AOSupplierReference',
));
}
树枝代码:
<span class="purchaseOrders">
{% for purchaseOrder in form.purchaseOrders %}
<span class="articleOrderReferences">
{% for articleOrderReference in form.articleOrderReferences %}
{{ form_errors(articleOrderReference.produced) }}
{{ form_widget(articleOrderReference.produced, { 'attr': {'class': 'input-mini'} }) }}
{% endfor %}<br>
</span>
{% endfor %}
</span>
控制器:
$form = $this->createForm(new ProducedAmountOrderType(), $order);
// // process the form on POST
// if ($request->isMethod('POST')) {
// $form->bind($request);
// if ($form->isValid()) {
// $em = $this->getDoctrine()->getManager();
// $em->persist($order);
// $em->flush();
// return $this->redirect($this->generateUrl('order', array('id' => $orderId )));
// }
// }
return $this->render('AcmeAppBundle:ProducedAmount:index.html.twig', array(
'form' => $form->createView(),
'order' => $order,
'articles' => $articles,
));
我评论了请求帖子,因为这只会导致空白页。现在我总是收到此错误消息:
Method "articleOrderReferences" for object "Symfony\Component\Form\FormView" does not exist in AcmeAppBundle:ProducedAmount:index.html.twig at line 150
我做错了什么?