Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/273.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Symfony 3.4-具有ChoiceType的PropertyAccessor异常_Php_Forms_Symfony - Fatal编程技术网

Php Symfony 3.4-具有ChoiceType的PropertyAccessor异常

Php Symfony 3.4-具有ChoiceType的PropertyAccessor异常,php,forms,symfony,Php,Forms,Symfony,这真的很奇怪。我得到以下异常: PropertyAccessor需要操作对象或数组的图形, 但它在尝试遍历路径“数量”时发现了类型“double” 属性“数量” 使用以下代码: $choices = array(); $minimumSaleUnit = $cartItem->getProduct()->getMinimumSaleUnit(); $maxItems = $cartItem->getProduct()->getQuantity(); for ($i =

这真的很奇怪。我得到以下异常:

PropertyAccessor需要操作对象或数组的图形, 但它在尝试遍历路径“数量”时发现了类型“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=array();
$minimumSaleUnit=$cartItem->getProduct()->getMinimumSaleUnit();
$maxItems=$cartItem->getProduct()->getQuantity();
对于($i=1;$i add('quantity',ChoiceType::class,['choices'=>$choices,'choice\u label'=>'quantity']))
->getForm();
$choices
是一个值数组:


因此,我不确定为什么会发生异常。我并不是在直接向它输入双精度。有什么想法吗?

这是错误指向的“choice_标签”定义-即,正如错误所说,choices数组中没有“Quantity”属性路径(请参阅)。其目的可能是只使用
“标签”=>“数量”

非常好的捕获!事实上,我盯着代码的这一部分,改变了所有内容,除了这个选项……哦,这将在晚上11点教我编码