【发布时间】:2012-07-21 15:09:39
【问题描述】:
我将 Symfony2 更新到 2.1,当我尝试提交表单时出现错误:
Choice 约束需要一个有效的回调
表单类型类的源代码:
$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';
}
}
有人可以给我任何建议吗?
【问题讨论】:
-
ChoiceList的实现好像变了。你看upgrade-2.1.md了吗?
标签: forms symfony-2.1