2012-07-23 2 views
2

나는 2.1 Symfony2 업데이트 내가 양식을 제출하려고 할 때 나는 오류가 점점 오전 : 폼 타입 클래스초이스 제약은 유효한 콜백에게 기대

The Choice constraint expects a valid callback

소스 코드 :

$builder->add('type', 'choice', 
        array(
         'expanded' => true, 
         'multiple' => false, 
         'choice_list' => new TypeChoices(), 
         'required' => true, 
        ) 
       ) 

TypeChoices 클래스를 :

class TypeChoices implements ChoiceListInterface { 

    public static $choices = array(
     'full-time' => 'Full time', 
     'part-time' => 'Part time', 
     'freelance' => 'Freelance', 
    ); 

    public static function getChoiceNameByValue($value) 
    { 
     return self::$choices[$value]; 
    } 

    public function getChoices() 
    { 
     return self::$choices; 
    } 

    public static function getTypeChoicesKeys() 
    { 
     return array_keys(self::$choices); 
    } 

    public static function getPreferredChoiceKey() 
    { 
     return 'full-time'; 
    } 
} 

누군가 나에게 조언을 제공 할 수 있습니까?

+0

구현 '변한 것으로 보인다. ['upgrade-2.1.md'] (https://github.com/symfony/symfony/blob/master/UPGRADE-2.1.md#other-bc-breaks)를 보았습니까? – gilden

답변

0

어쩌면 당신이 SimpleChoiceList 클래스를 확장을 시도 할 수 있습니다,이 방법 :

ChoiceList 코드 :

class TypeChoices extends SimpleChoiceList 
{ 
    public static $choices = array(
     'full-time' => 'Full time', 
     'part-time' => 'Part time', 
     'freelance' => 'Freelance', 
    ); 

    /** 
    * Constructor. 
    * 
    * @param array $preferredChoices Preffered choices in the list. 
    */ 
    public function __construct(array $preferredChoices = array()) // PASS MORE ARGUMENT IF NEEDED 
    { 
     parent::__construct(
      static::$choices, 
      $preferredChoices 
     ); 
    } 
} 

양식 유형 코드 : ChoiceList`의

->add('type', 'choice', array(
    'choice_list' => new TypeChoices(), 
    ... 
))