yii的rules验证规则
- 图片验证
public function rules() { return [ [['id'], 'integer'], [['id'], 'required'], [['files'], 'file', 'maxSize' => 50 * 1024 * 1024, 'maxFiles' => 10, 'mimeTypes' => ['image/*', 'audio/*', 'video/*']], ]; }
- 场景验证
public function rules() { return [ [['username','password'],'required','on'=>'login'] ] } public function exec(){ $this->scenario = "login"; if (!$this->validate()) { return [ 'errors' => $this->errors, ]; } }
- 对指定字段规定范围验证
public function rules() { return [ ['week', 'in', 'range' => [1,2,3,4,5,6,7]] ];