我不明白一些奇怪的 Symfony2 行为。假设有一个实体产品:
class Product
{
/** Some doctrine things */
protected $id;
/** Some doctrine things */
private $title;
/**
* @ORM\Column(type="decimal", precision=10, scale=2)
* @Assert\NotBlank(message="This field cannot be empty.")
* @Assert\GreaterThan(value=0, message="Please enter an amount higher than 0.")
*/
private $price;
/** Getters and setters */
}
要添加产品,我正在使用表单 ProductType,使用此表单:
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('title', 'text')
->add('price', 'money', array('currency' => false, 'invalid_message' => 'Please enter a valid value.'))
}
一切正常,除非我提交一些无效值:
- 1foo按预期生成“请输入有效值。”
- foo1生成内部服务器错误:“警告:NumberFormatter::parse(): Number parsing failed”
- foo生成内部服务器错误:“警告:NumberFormatter::parse(): Number parsing failed”
我在本地 WampServer 上使用 SF2 v2.6。