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.

This commit is contained in:
wenbin1989
2014-08-18 15:12:15 +08:00
committed by Qiang Xue
parent 385e13978d
commit 3b705855aa

View File

@ -102,9 +102,12 @@ class BlameableBehavior extends AttributeBehavior
protected function getValue($event)
{
if ($this->value === 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);
}