我正在尝试为实体创建管理页面。
在实体Settings
中,我有一个字段calculatorItems
/**
* @var
* @ORM\OneToMany(targetEntity="AppBundle\Entity\FuneralCostResource", mappedBy="settings")
*/
private $calculatorItems ;
public function __construct()
{
$this->calculatorItems = new ArrayCollection();
}
在SettingsAdmin
中,我声明了“计算器”标签
->tab('Calculator')
->add('calculatorItems', 'collection',[
'by_reference' => false,
'allow_add' => true,
'allow_delete' => true,
'prototype' => true,
'entry_type' => CalculatorType::class
])
这是计算器类型
class CalculatorType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('resourceName', NumberType::class)
->add('resourcePrice');
}
public function configureOptions(OptionsResolver $resolver)
{
}
public function getBlockPrefix()
{
return 'app_bundle_calculator_type';
}
}
当我尝试为设置添加新记录或更新现有记录时,出现异常:
Expected value of type "Doctrine\Common\Collections\Collection|array" for association field "AppBundle\Entity\Settings#$calculatorItems", got "array" instead.
但是calculatorItems
是一个ArrayCollection而不是数组。