Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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,
        ],
    ],
];
like image 335
Prakash Shinde Avatar asked Aug 05 '17 11:08

Prakash Shinde


1 Answers

Make sure the ActiveRecord object you are using (the one in static::findOne(...)) is an instance of yii\mongodb\ActiveRecord and not yii\db\ActiveRecord because the latter uses standard db component I assume you have not got configured.

like image 80
Bizley Avatar answered Oct 22 '22 18:10

Bizley