【问题标题】:Symfony 2 Number Field with validation constraint not working带有验证约束的 Symfony 2 数字字段不起作用
【发布时间】:2015-01-15 11:41:30
【问题描述】:

我尝试在数字字段中插入一个字符串来进行验证,但它不起作用

/**
     * @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"

我正在使用带有 php 5.5 的服务器上安装了 INTL 扩展的 symfony 2.4

【问题讨论】:

    标签: php symfony symfony-2.4


    【解决方案1】:

    我指定了要考虑的验证组

    /**
         * @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;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-08-17
      • 2019-06-08
      • 1970-01-01
      • 1970-01-01
      • 2012-05-17
      • 2012-11-13
      • 1970-01-01
      相关资源
      最近更新 更多