Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when the instance of a model is created - Softdelete and Blameable Behavior #148

Open
MarcoPro opened this issue Sep 20, 2018 · 1 comment

Comments

@MarcoPro
Copy link

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?

@MarcoPro
Copy link
Author

MarcoPro commented Mar 6, 2019

Has anyone else had this problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant