Open MarcoPro opened 6 years ago
When I use a model in a console method with softdelete or Blameable Behavior (\Yii::$app->user->id), the following error appears:
'Getting unknown property: yii \ console \ Application :: user'
I have solved it by adding the user component in the console and manually adding the identity in the console command, but I do not know if it is the most appropriate solution.
console/config/main.php
'components' => [ ......... ...... 'user' => [ 'class' => 'yii\web\User', 'identityClass' => 'app\models\User', //'enableAutoLogin' => true, ], ....... ]
console method
$identity = \app\models\User::findIdentity('<service_user_id>'); if ($identity === null) { throw new ForbiddenHttpException; } \Yii::$app->user->setIdentity($identity);
Any suggestions?
Has anyone else had this problem?
When I use a model in a console method with softdelete or Blameable Behavior (\Yii::$app->user->id), the following error appears:
I have solved it by adding the user component in the console and manually adding the identity in the console command, but I do not know if it is the most appropriate solution.
console/config/main.php
console method
Any suggestions?