Exception Setting unknown property identityclass


I am getting this Error:
Exception 'yii\base\UnknownPropertyException' with message 'Setting unknown property: common\models\User::identityClass'

The error seems to be in the configuration:

'controllerNamespace' => 'console\controllers',

    'components' => [

        'log' => [

            'targets' => [
                    'class' => 'yii\log\FileTarget',
                    'levels' => ['error', 'warning', 'info'],

            'user' => [
                    'identityClass' => 'common\models\User', // ISSUE SEEMS TO BE HERE
                    'class' => 'common\models\User',
                    'enableAutoLogin' => true,
            'authManager' => [
                    'class' => 'yii\rbac\PhpManager',

                    'defaultRoles' => ['admin','editor','user'], // here define your roles

                'itemFile' => '@console/data/items.php', //Default path to items.php | NEW CONFIGURATIONS
                'assignmentFile' => '@console/data/assignments.php', //Default path to assignments.php | NEW CONFIGURATIONS
                'ruleFile' => '@console/data/rules.php', //Default path to rules.php | NEW CONFIGURATIONS

But disabling that line is not working. It appears another error. It is weird because it was not happening before. But I am assuming that it is because I am using the User model, which I was not using before, but still, everything else is working. If you require any other information to help me, please just ask me.

I am not sure of what it is so I don’t really know what else might help solve this problem.

You have to implement yii\web\IdentityInterface

Read the following section of the Guide.
Guide > Security > Authentication

BTW, 'class' => 'common\models\User' in the configuration looks odd to me. I never wrote a line like this for the configuration of ‘user’. What’s this?

It is actually implemented.

We’ve already figured out what was going on. The service was calling another service, that was calling a function in a model. This function was calling Yii::$app->user->id. And since it was in console, this was causing issues.

I just had to add

if (Yii::$app instanceof \yii\console\Application){

Also regarding your question, I’m not sure either. This is something that was there from before and I’m not sure about how the configuration works. Though common\models\User has the implementation of the class User that extends ActiveRecord and impleents IdentityInterface.

Mainly, the issues we have had were regarding it being console and non-console. The functions were orginally created for non-console, and now that we need some functionality in console, these functions were not ready for in-console usage.

1 Like

I see. :thinking:

There is no Yii::$app->user available in a console app. For example you can’t have Yii::$app->user->isGuest because there is no session or login in a console app.