YII rules 'required' and 'default'


(suchang1995) #1

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 。


(Alexander Makarov) #2

What exactly is not compatible currently?


(suchang1995) #3

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 。


(Softark) #4

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.


(suchang1995) #5

OK,i get it! THANKS!!!