我想要表示一對多關係以使用採購訂單持久化採購訂單deatils.So我嘗試通過爲每個細節增加一個錶行來添加採購訂單明細列表。 , 我開發PurchaseOrderDetailType形式類型如下無法加載自定義表單字段在Symfony 3中鍵入
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
所以,如果你正在使用的Symfony 3或Symfony的2.8和的EntityType ::類語法,你必須把命名空間 - '使用的Symfony \橋\原則\表格\型號\ EntityType;' –
是的,我已經正確導入了所有庫。我沒有在這裏提及它們。 – Sameera