user4985526
user4985526

Reputation:

Yii2 validation rule in model have multiple scenarios

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

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

I read the guide , haven't find a way to bind a rule to 2 scenarios at the same time? Is there any way to do that ?

Upvotes: 12

Views: 4232

Answers (1)

arogachev
arogachev

Reputation: 33538

You can pass an array to on:

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

Upvotes: 17

Related Questions