* @since 2.0 */ class DefaultValueValidator extends Validator { /** * @var mixed the default value to be set to the specified attributes. */ public $value; /** * @var boolean this property is overwritten to be false so that this validator will * be applied when the value being validated is empty. */ public $skipOnEmpty = false; /** * Validates the attribute of the object. * @param \yii\base\Model $object the object being validated * @param string $attribute the attribute being validated */ public function validateAttribute($object, $attribute) { if ($this->isEmpty($object->$attribute)) { $object->$attribute = $this->value; } } }