在app / models / Model中 这验证了
//simulating incorrect user input
//$model->status='some-string';
public function rules()
{
return [
['status', 'in', 'range' => [0]], //asserts true (why?)
//['status', 'in', 'range' => [0], 'strict' => true], //asserts false (correct)
];
}
编辑:我已更新此问题以反映新的见解。
答案 0 :(得分:0)
请确保在模型类中定义常量
class model extends activeRecord {
const STATUS = 0;
public function rules()
{
return [
[['status'], 'in', 'range' => [self::STATUS]],
];
}
}
试试这个对我有用.....
答案 1 :(得分:0)
状态很可能为空,内部检查计算为:
// non-strict:
null == 0 // this is true
// strict:
null === 0 // this is false
同样适用于空字符串,请参阅related question