我想表示一对多的关系以保持采购订单与采购订单详细信息。所以我尝试通过为每个详细信息增加一个表格行来添加采购订单详细信息列表。为此,我开发了 PurchaseOrderDetailType 表单类型如下
class PurchaseOrderDetailType extends AbstractType{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('item',EntityType::class, array(
'class' => 'AppBundle:InvtItem',
'query_builder' => function (EntityRepository $er) {
return $er->createQueryBuilder('item')
->orderBy('item.description', 'ASC');
},
'choice_label' => 'description',
))
->add('unit_price')
->add('qty')
->add('price');
}
/**
* @param OptionsResolver $resolver
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'AppBundle\Entity\PurchaseOrderDetails'
));
}
}
然后我像这样在 PurchaseOrderType 类中使用它
class PurchaseOrderType extends AbstractType
{
/**
* @param FormBuilderInterface $builder
* @param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('supplier',EntityType::class, array(
'class' => 'AppBundle:Supplier',
'label'=>'Supplier',
'query_builder' => function (EntityRepository $er) {
return $er->createQueryBuilder('supplier')
->orderBy('supplier.name', 'ASC');
},
'choice_label' => 'name',
))
->add('purchaseOrderDetails',CollectionType::class,array(
'entry_type' => PurchaseOrderDetailType::class,
'allow_add' => true
))
->add('status');
}
/**
* @param OptionsResolver $resolver
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'AppBundle\Entity\PurchaseOrder'
));
}
}
然后我收到此错误 => 无法加载类型“PurchaseOrderDetailType”500 内部服务器错误 - InvalidArgumentException