2012-04-19 53 views
0

當我訪問我的瀏覽器,這是我所得到的:Symfony2的致命錯誤

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

是文件它正在引用......關於這個問題可能有什麼想法?

回答

1

我相信在Symfony 2.1中FormTypeInterface已經發生了變化。

getDefaultOptions不再有參數。

UPGRADE-2.1 document


方法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; 
     } 
    ); 
}