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