Yii2 dependency custom rule validation
问题 I have two input fields consider A and B , now i want to validate that user can input at least one field that is either A or B field. Is there a way to create a rule condition? 回答1: Add like this in rules public function rules() { return [ [['field_A'],'required','when' => function($model) { return $model->field_B == NULL; }, 'message' => 'Either field_A or field_B is required.'], [['field_B'],'required','when' => function($model) { return $model->field_A == NULL; }, 'message' => 'Either