我不知道我是在面对一个错误还是做错了什么。我正在尝试从自定义类加载ChoiceType表单的选项,但是我收到以下错误:
Catchable Fatal Error: Argument 1 passed to Symfony\Component\Form\ChoiceList\LazyChoiceList::__construct() must be an instance of Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface, none given
我的自定义课程:
<?php
namespace AppBundle\Form\ChoiceLists;
use Symfony\Component\Form\ChoiceList\SimpleChoiceList;
use Symfony\Component\Form\ChoiceList\LazyChoiceList;
class DepartmentsChoiceList extends LazyChoiceList
{
public function loadChoiceList()
{
$choices = array(
'01' => "Ain",
'02' => "Aisne",
'03' => "Allier",
'04' => "Alpes de Haute Provence",
'05' => "Alpes (Hautes)",
//....
'94' => "Val de Marne",
'95' => "Val d´Oise",
'98' => "Mayotte",
'9A' => "Guadeloupe",
'9B' => "Guyane",
'9C' => "Martinique",
'9D' => "Réunion",
);
return new SimpleChoiceList($choices);
}
}
在我的formType中:
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('birthDepartment', ChoiceType::class, array(
'label' => 'Département :',
'required' => false,
'choices' => new DepartmentsChoiceList(),
)
);
我发现此功能的文档很少。