Forms symfony2表单声明中的致命错误

Forms symfony2表单声明中的致命错误,forms,symfony,Forms,Symfony,当我访问我的浏览器时,我得到的是: Fatal error: Declaration of Ecs\CrmBundle\Form\Parts\DepartmentSelectionType::getDefaultOptions() must be compatible with Symfony\Component\Form\FormTypeInterface::getDefaultOptions() in C:\wamp\www\crm\src\Ecs\CrmBundle\Form\Parts\

当我访问我的浏览器时,我得到的是:

Fatal error: Declaration of Ecs\CrmBundle\Form\Parts\DepartmentSelectionType::getDefaultOptions() must be compatible with Symfony\Component\Form\FormTypeInterface::getDefaultOptions() in C:\wamp\www\crm\src\Ecs\CrmBundle\Form\Parts\DepartmentSelectionType.php on line 41
其引用的文件如下所示:

<?php

namespace Ecs\CrmBundle\Form\Parts;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilder;


class DepartmentSelectionType extends AbstractType {
    private $canSeeAll = false;

    public function __construct($canSeeAll = false)
    {
        $this->canSeeAll = $canSeeAll;
    }

    public function buildForm(FormBuilder $builder, array $options)
    {
        $builder
            ->add('department', 'entity',
                array(
                    'class' => "EcsAgentManagerBundle:EmployeeDepartment",
                    'required' => false,
                    'multiple' => true,
                    'expanded' => true,
                    'label' => "Department"))
        ;
    }

    public function getDefaultOptions(array $options)
    {
        return array(
            'data_class' => 'Ecs\AgentManagerBundle\Entity\EmployeeDepartment',
        );
    }

    public function getName()
    {
        return 'ecs_crmbundle_departmentselectiontype';
    }
}

我相信在Symfony 2.1中,FormTypeInterface已经改变了

不再需要争论

从:


form的方法getDefaultOptions()和getAllowedOptionValues() 类型不再接收选项数组

可以使用闭包指定依赖于其他选项的选项 相反

之前

public function getDefaultOptions(array $options)
{
    $defaultOptions = array();

    if ($options['multiple']) {
        $defaultOptions['empty_data'] = array();
    }

    return $defaultOptions;
}
public function getDefaultOptions()
{
    return array(
        'empty_data' => function (Options $options, $previousValue) {
            return $options['multiple'] ? array() : $previousValue;
        }
    );
}
之后

public function getDefaultOptions(array $options)
{
    $defaultOptions = array();

    if ($options['multiple']) {
        $defaultOptions['empty_data'] = array();
    }

    return $defaultOptions;
}
public function getDefaultOptions()
{
    return array(
        'empty_data' => function (Options $options, $previousValue) {
            return $options['multiple'] ? array() : $previousValue;
        }
    );
}