Commit 3b705855 by wenbin1989 Committed by Qiang Xue

fix bugs of BlameableBehavior in console application. In console application,…

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.
parent 385e1397
...@@ -102,10 +102,13 @@ class BlameableBehavior extends AttributeBehavior ...@@ -102,10 +102,13 @@ class BlameableBehavior extends AttributeBehavior
protected function getValue($event) protected function getValue($event)
{ {
if ($this->value === null) { if ($this->value === null) {
if (Yii::$app->hasMethod('getUser')) {
$user = Yii::$app->getUser(); $user = Yii::$app->getUser();
return $user && !$user->isGuest ? $user->id : null; return $user && !$user->isGuest ? $user->id : null;
} else { } else {
return null;
}
} else {
return call_user_func($this->value, $event); return call_user_func($this->value, $event);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment