Yii2 mongodb error Object configuration must be an array containing a "class" element

时间:2017-08-05 11:25:16

标签: mongodb yii2

When I try to login OR Signup it does not work. If I try to login with wrong credential it works. But if I use right credential it gives error:

Object configuration must be an array containing a "class" element.

Error on line:

 static::findOne(['username' => $username, 'status' => self::STATUS_ACTIVE]);

and related line

$models = $this->createModels($rows);

My config is as below

main.php

return [
  'vendorPath' => dirname(dirname(__DIR__)) . '/vendor',
  'components' => [
    'cache' => [
        'class' => 'yii\caching\FileCache',
    ],
  ],
];

main-local.php

return [
    'components' => [
        'mongodb' => [
            'class' => '\yii\mongodb\Connection',
            'dsn' => 'mongodb://mts:123456@localhost:27017/mangodb',
        ],
        'user' => [
            'identityClass' => 'common\models\User', // This is your class with IdentityInterface
            'enableAutoLogin' => true,
        ],
    ],
];

1 个答案:

答案 0 :(得分:3)

请确保您使用的ActiveRecord对象(static::findOne(...)中的一个)是yii\mongodb\ActiveRecord的实例,并且不是 yii\db\ActiveRecord的实例,因为后者使用标准的{ {1}}组件我认为您尚未配置。