The Yii2 validation rule in the model has several scenarios

I have 3 scenarios in the model in the rules () method, and I want to use the rule in 2 scenarios,

[['username', 'email', 'password'], 'required', 'on' => self::SCENARIO_REGISTER] 

I read the manual, did not find a way to bind the rule to two scenarios at the same time? Is there any way to do this?

+7
yii2 model
source share
1 answer

You can pass an array to on :

 [['username', 'email', 'password'], 'required', 'on' => [self::SCENARIO_REGISTER, self::SCENARIO_OTHER]] 
+10
source share

All Articles