答案 0 :(得分:0)
->add('projects', ChoiceType::class, [
'choices' => $this->getAllProjects(),
'choice_label' => function($choice, $key, $value) {
return $value->getName(); // you know your getter
//return $value['name']; //if the return of the getAllProjects is an associative array
},
])
关键是,匿名函数中的$ value是来自可数对象(来自“选择”)的一个元素: