0

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

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';
    }
}

是它引用的文件...关于问题可能是什么的任何想法?

4

1 回答 1

1

我相信 FormTypeInterface 在 Symfony 2.1 中发生了变化。

getDefaultOptions不再需要争论。

UPGRADE-2.1 文档


表单类型的 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;
        }
    );
}
于 2012-04-19T00:24:07.190 回答