1

Some of the changes in craft 3 have been killing me. I know Yii does validation using the public rules function. Here is a rules function I grabbed from the MatrixBlockType model.

function rules()
{
    return [
        [['id', 'fieldId', 'sortOrder'], 'number', 'integerOnly' => true],
    ];
}

My question is simple. I for the life of me can't find where the validator number is defined. I'm assuming it validates using Yii's NumberValidator.php function but can't verify that. Any ideas on where I can find the number validator?

2

I just figured out the answer so I'm going to post it if anyone else is asking this question. Yii accepts aliases as well as function/class names when evaluating the rules function. When using number you're really using an alias that points to the yii\validators\NumberValidator class. See yii2/validators/Validator.php to see a list of default aliases created by Yii.

  • Great that you got it solved! If it works, go ahead and mark your own answer as "correct" so that it shows up as a solved issue. – KSP Nov 10 '18 at 22:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.