From 3b705855aaf5f4260c92c43de415fdd39c9dd8b7 Mon Sep 17 00:00:00 2001 From: wenbin1989 Date: Mon, 18 Aug 2014 15:12:15 +0800 Subject: [PATCH] fix bugs of BlameableBehavior in console application. In console application, \yii\console\Application doesn't have `getUser()` method. Use BlameableBehavior in console application will cause an exception. --- framework/behaviors/BlameableBehavior.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/framework/behaviors/BlameableBehavior.php b/framework/behaviors/BlameableBehavior.php index 791a07748a..bd4c5b8b2e 100644 --- a/framework/behaviors/BlameableBehavior.php +++ b/framework/behaviors/BlameableBehavior.php @@ -102,9 +102,12 @@ class BlameableBehavior extends AttributeBehavior protected function getValue($event) { if ($this->value === null) { - $user = Yii::$app->getUser(); - - return $user && !$user->isGuest ? $user->id : null; + if (Yii::$app->hasMethod('getUser')) { + $user = Yii::$app->getUser(); + return $user && !$user->isGuest ? $user->id : null; + } else { + return null; + } } else { return call_user_func($this->value, $event); }