Symfony 2 Number字段,验证约束不起作用

时间:2015-01-15 11:41:30

标签: php symfony symfony-2.4

我尝试在数字字段中插入一个字符串来验证验证,但它无法正常工作

/**
     * @Assert\Length(max = "16")
     * @Assert\NotBlank(groups={"specific"},message="Le montant doit etre renseigné")
     * @Assert\Type(type="numeric", message="La valeur {{ value }} n'est pas un nombre.")
     *
     * @var decimal $amount
     *
     * @ORM\Column(name="amount", type="decimal", length=16, nullable=true)
     */
    private $amount;

每次提交论坛我都有一个postgresql错误:

SQLSTATE[22P02]: Invalid text representation

我期待着下面的消息

"The value is xxx not a number"

我正在使用symfony 2.4并使用php 5.5

在serveur上安装INTL扩展

1 个答案:

答案 0 :(得分:0)

我指定验证组将其纳入帐户

/**
     * @Assert\Length(max = "9")
     * @Assert\Type(groups={"avantage"},type="numeric", message="La valeur {{ value }} n'est pas un nombre.")
     * @Assert\NotBlank(groups={"avantage"},message="Le montant doit etre renseigné")
     *
     * @var decimal $amount
     *
     * @ORM\Column(name="amount", type="decimal", length=16, nullable=true)
     */
    private $amount;