这真奇怪。我得到了以下异常:
PropertyAccessor需要操作对象或数组的图形,
但它在尝试遍历路径“quantity”时发现类型“double”
属性“数量”。
使用以下代码:
$choices = array();
$minimumSaleUnit = $cartItem->getProduct()->getMinimumSaleUnit();
$maxItems = $cartItem->getProduct()->getQuantity();
for ($i = 1; $i <= 20; $i++) {
$value = $i * $minimumSaleUnit;
if ($value <= $maxItems) {
$choices["$value"] = $value;
}
}
$form = $this->createFormBuilder($cartItem)
->add('quantity', ChoiceType::class, ['choices' => $choices, 'choice_label' => 'Quantity'])
->getForm();
$choices
是
值数组:
所以我不确定为什么会发生异常。我可不像是直接给它喂食。有什么想法吗?