2017-03-16 87 views
0

看起来好像有错误或文档是错误的。只需在此发布以确认这是一个错误。 ChoiceType ::类Symfony ChoiceType选择标签不接受字符串作为值

$choice1 = new \stdClass(); 
$choice1->name = 'Shipping'; 
$choice1->label = 'Shipping for you'; 
$choice1->code = 'xyz'; 

$builder 
    ->add('modeOfDelivery', ChoiceType::class, [ 
    'choices' => [ 
     $choice1 
    ], 
    'choice_label' => 'label', 
    'choice_value' => 'code' 
    ]) 
; 

当试图用一个字符串作为CHOICE_LABEL值我得到这个PHP的错误:Expected argument of type "null or callable", "string" given

在供应商

/symfony中/ symfony中/ src目录/ Symfony的/分量/表格/选择列表/第70行的ArrayChoiceList.php -

public function __construct($choices, $value = null) 
    { 
     if (null !== $value && !is_callable($value)) { 
      throw new UnexpectedTypeException($value, 'null or callable'); 
     } 

任何帮助将不胜感激。

回答

1

缺少choices_as_values选项。这在2.8版本中被要求使用对象作为选择。