简体   繁体   English

最小数量验证器在Yii2模型中不起作用

[英]Minimum number validator is not working in Yii2 model

[['price'], 'integer', 'min' => 0, 'tooSmall' => 'Price cannot be less than 0'],

I have above rule in my model file. 我的模型文件中有上述规则。 But while validating the model, return is true while passed NULL as price. 但是,在验证模型时,将NULL作为价格传递时return为true

Any reason to this? 有什么理由吗?

如果即使在字段为空的情况下也想进行验证,请将skipOnEmpty设置为false (默认情况下设置为true )。

[['price'], 'integer', 'skipOnEmpty' => false, 'min' => 0, 'tooSmall' => 'Price cannot be less than 0'],

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM