yii\validators\RangeValidator::validateAttribute PHP Method

validateAttribute() public method

public validateAttribute ( $model, $attribute )
    public function validateAttribute($model, $attribute)
    {
        if ($this->range instanceof \Closure) {
            $this->range = call_user_func($this->range, $model, $attribute);
        }
        parent::validateAttribute($model, $attribute);
    }

Usage Example

Beispiel #1
0
 public function testValidateAttribute()
 {
     $val = new RangeValidator(['range' => range(1, 10, 1)]);
     $m = FakedValidationModel::createWithAttributes(['attr_r1' => 5, 'attr_r2' => 999]);
     $val->validateAttribute($m, 'attr_r1');
     $this->assertFalse($m->hasErrors());
     $val->validateAttribute($m, 'attr_r2');
     $this->assertTrue($m->hasErrors('attr_r2'));
     $err = $m->getErrors('attr_r2');
     $this->assertTrue(stripos($err[0], 'attr_r2') !== false);
 }