我試圖使用liform或liform-bundle產生在我的控制我的表單類型的JSON的JSON,但得到的錯誤:找我FormType模式
嚴重 - 捕獲的PHP異常的Symfony \分量\調試\ Exception \ UndefinedMethodException:「試圖調用類」Symfony \ Component \ Form \ Extension \ DataCollector \ Proxy \ ResolvedTypeDataCollectorProxy「中名爲」getBlockPrefix「的未定義方法。在/home/admin/Documents/displayce/code/vendor/limenius/liform/src/Limenius/Liform/FormUtil.php線39
代碼在我的控制器:
$form = $this->createForm(new FormType(), $entity, array(
'method' => 'PUT',
'csrf_protection' => false,
));
$schema = json_encode($this->get('liform')->transform($form));
我的表單類型代碼:
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('startDate', 'date', array(
'label' => 'Start Date',
'required' => false,
'widget' => 'single_text',
'format' => 'dd/MM/yyyy',
'input' => 'datetime',
))
->add('endDate', 'date', array(
'label' => 'End Date (included)',
'required' => false,
'widget' => 'single_text',
'format' => 'dd/MM/yyyy',
'input' => 'datetime',
))
->add('name', 'text', array(
'label' => 'Name',
'max_length' => 255,
))
->add('budget', 'money', array(
'label' => 'Budget (target)',
'required' => true,
'scale' => 0, // not showing decimals
))
->add('target', 'targeting', array(
'cascade_validation' => true,
));
}
和定位類型:
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('contexts', 'entity', array(
'label' => 'Context(s)',
'class' => 'AppBundle\Entity\Context',
'choice_label' => 'name',
'expanded' => false,
'multiple' => true,
'required' => false,
))
->add('contextDetails', 'entity', array(
'label' => 'Detailed Context(s)',
'class' => 'AppBundle\Entity\ContextDetail',
'choice_label' => 'name',
'group_by' => 'context.name',
'expanded' => false,
'multiple' => true,
'required' => false,
))
->add('dataVariables', 'entity', array(
'label' => 'Variable',
'class' => 'AppBundle\Entity\DataVariable',
'choice_label' => 'name',
'expanded' => false,
'multiple' => true,
'group_by' => function($dataVariable, $key, $index) {
return $dataVariable->getDataProvider()->getName();
}
))
// Include criteria
->add('region', 'choice', array(
'label' => 'Region(s)',
'choices' => RegionDepartment::$regions,
'expanded' => false,
'multiple' => true,
'required' => false,
))
->add('department', 'choice', array(
'label' => 'Department(s)',
'choices' => RegionDepartment::$departments,
'expanded' => false,
'multiple' => true,
'required' => false,
))
;
這可能是因爲我使用嵌套的formtype?
我的目標是如果將symfony FormType和React Component結合起來,只要您可以將我重定向到一個解決方案來做到這一點,我會很高興。
「試圖調用類」Symfony \ Component \ Form \ Form「中名爲」getBlockPrefix「的未定義方法。」 我沒有在Form.php中的功能,所以我不能訪問它 –
我正在使用symfony 2.7,它是一個函數,我將在一個更新的版本或我有一個較舊的版本? –
更新到Symfony 2.8將解決您的問題。 – xabbuh