I'm using Yii2 validator to validate my attributes. I have an validator rule, which should be fire on an specific scenario by using $model->validate('run_special_validation');
and also at the default scenario when running $model->validate();
I know, that I can define the scenarios like this:
public function rules() {
return [
['name', 'required', 'on' => 'run_special_validation'],
['email', 'required'],
];
}
What I need is to run the validation for name
separately, for example by using $model->validate('run_special_validation')
and also together with all other validations by running $model->validate()
.
//Edit: I know, there is an "ad hoc" validation available in Yii2, which maybe could be used. (https://www.yiiframework.com/doc/guide/2.0/en/input-validation#ad-hoc-validation) But is there a way to do that insight the model scope?