Yii2: Cannot use BlameableBehavior when AR is accessed by a console app

Created on 8 Oct 2014  路  8Comments  路  Source: yiisoft/yii2

I am getting this error 'Calling unknown method: yiiconsoleApplication::getSession()' when i run a console app that updates an AR that has a BlameableBehavior.

TIA.

Most helpful comment

you can check Yii::$app instanceof \yii\console\Application

All 8 comments

That's expected since there's no session in console.

@samdark does it mean i cannot update that AR via a console app? thanks!

i mean i can't use BlameableBehavior then, right? thanks!

you have to set the user attribute of the behavior yourself because yii can not detect the current user from Yii::$app->user there.

any way i can detect if it is from console app? thanks.

you can check Yii::$app instanceof \yii\console\Application

saves my day. thanks much @cebe @samdark

saves my day. thanks much @cebe @samdark

How did you solve the problem? Would you mind to share here your solution?

Was this page helpful?
0 / 5 - 0 ratings