diff --git a/framework/yii/behaviors/AutoTimestamp.php b/framework/yii/behaviors/AutoTimestamp.php index 432527a5a5..cf8c33e963 100644 --- a/framework/yii/behaviors/AutoTimestamp.php +++ b/framework/yii/behaviors/AutoTimestamp.php @@ -99,4 +99,18 @@ class AutoTimestamp extends Behavior return time(); } } + + /** + * Updates a timestamp attribute to the current timestamp. + * + * ```php + * $model->touch('lastVisit'); + * ``` + * @param string $attribute the name of the attribute to update. + */ + public function touch($attribute) + { + $timestamp = $this->evaluateTimestamp(); + $this->owner->updateAttributes([$attribute => $timestamp]); + } }