YII rules 'required' and 'default'

this is my code:
image

i think Yii Framework can Compatible this maby. Am I wrong?
i think Yii Framework should do ‘isDefault’ = 0 when ‘isDefault’ is not in queryBody.but now ‘{“field”:“isDefault”,“message”:“isDefault Can not be empty”}’ i get 。

What exactly is not compatible currently?

i think Yii Framework should do ‘isDefault’ = 0 when ‘isDefault’ is not in queryBody.but now ‘{“field”:“isDefault”,“message”:“isDefault Can not be empty”}’ i get 。

You don’t need the 1st line, because you want ‘isDefault’ to be 0 when it is empty.

// ['isDefault' => 'required'],
['isDefault' => 'default', 'value' => 0],

Or you may try this for testing purpose:

['isDefault' => 'default', 'value' => 0],
['isDefault' => 'required'],

Then the ‘default’ validator will be applied before ‘required’ validator, because the rules are applied in the order of appearance.

1 Like

OK,i get it! THANKS!!!