From 01d0323521b591284f70ef2bb1f07af13a8498c2 Mon Sep 17 00:00:00 2001 From: Carsten Brandt Date: Tue, 7 Jan 2014 05:10:36 +0100 Subject: [PATCH] added laravel like touch() method to AutoTimestamp --- framework/yii/behaviors/AutoTimestamp.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/framework/yii/behaviors/AutoTimestamp.php b/framework/yii/behaviors/AutoTimestamp.php index 432527a..cf8c33e 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]); + } }