2
我更新的Symfony2到2.1,當我試圖提交表單我得到錯誤:從表單類型級的選擇約束需要一個有效的回調
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';
}
}
有人能給我任何建議嗎?
選擇列表的'實施'似乎已經改變了。你看過['upgrade-2.1.md'](https://github.com/symfony/symfony/blob/master/UPGRADE-2.1.md#other-bc-breaks)嗎? – gilden 2012-07-23 14:13:53