php - 最小数量验证器在 Yii2 模型中不起作用
问题描述
[['price'], 'integer', 'min' => 0, 'tooSmall' => 'Price cannot be less than 0'],
我的模型文件中有上述规则。但是在验证模型时,回报是作为价格true
传递的。NULL
这有什么理由吗?
解决方案
如果您想在字段为空时进行验证,请设置为(默认情况下设置为skipOnEmpty
)。false
true
[['price'], 'integer', 'skipOnEmpty' => false, 'min' => 0, 'tooSmall' => 'Price cannot be less than 0'],
推荐阅读
- c++ - 声明一个枚举类底层类型 bool 有什么好处?
- r - 有没有办法根据 R 上的相同字符获取不同文件的列表并将它们组合在一个单独的列表中?
- c++ - Qt Creator:找不到 Qt3DExtras 模块
- vue.js - 我有一个 vue.js 错误
- python - 引用前一个参数的 Python 默认参数
- asp.net - 从 React 使用 API POST 到 ASP.net 控制器时总是得到 400 错误
- sharepoint - Sharepoint 连接器未显示在 Azure 逻辑应用程序中
- java - 在 Eclipse IDE 中重命名为大写
- reactjs - 在 tsx 中导入 jsx
- python - 给定单词的平均字符