2amigos / yii2-usuario

Highly customizable and extensible user management, authentication, and authorization Yii2 extension
https://github.com/2amigos/yii2-usuario
Other
292 stars 141 forks source link

'Object configuration must be an array containing a "class" or "__class" element.' #363

Open larry-tx opened 4 years ago

larry-tx commented 4 years ago

What steps will reproduce the problem?

  1. Install yii2-usuario via composer require 2amigos/yii2-usuario:~1.0. Also tried composer require 2amigos/yii2-usuario: 'dev-master' to see if it would make a difference with dev-master; no difference.

  2. Modify %PROJECT_DIR%/console/config/main.php to read as follows:

    'controllerMap' => [
                'fixture' => [
                    'class'     => 'yii\console\controllers\FixtureController',
                    'namespace' => 'common\fixtures',
                ],
                'migrate' => [
                    'class'               => 'yii\console\controllers\MigrateController',
                    'migrationPath'       => [
                        '@app/migrations',
                        '@yii/rbac/migrations',
                    ],
                    'migrationNamespaces' => [
                        'Da\User\Migration',
                    ],
                ],
            ],
  3. Attempt to run the migrations via yii migrate.

What is the expected result?

rbac and usario migrations run to produce required tables.

What do you get instead?

Error message stating:

Exception 'yii\base\InvalidConfigException' with message 'Object configuration must be an array containing a "class" or "__class" element.'

Comments

First, I have attempted to find a solution for this ubiquitous problem. Nothing I've fond seems to work or be relevant. Hope someone can help.

This seems to be an upgrade-related issue because it worked just fine on another website on a previous version of Yii2. For what it's worth, here's the stats:

Any help will be most appreciated. If I can find a way to work around the migration problems, I can create the tables using the migrations as a model. However, I feel like I will likely encounter this same issue elsewhere.

maxxer commented 4 years ago

Config appears correct. The only option which comes to my mind is the presence of some weird character in the text, like in the class line or something like that. Try retyping the whole row in a new line from scratch

larry-tx commented 4 years ago

Thanks, @maxxer , but it gets even worse. I got to thinking, What if the problem is in the rbac migration since this approach would involve it as well. (I only wish the Yii2 stack trace would pinpoint the actual source of the error instead of pointing back to core modules which is almost always totally useless information.) So I commented out the rbac migration in migrationpath. Same error. Then, I tried the reverse with usuario commented out and rbac uncommented. Same error. Then I commented out all the migrationPath and migrationNamespaces and tried running yii migrate --migrationPath=@yii/rbac/migrations. Same error. Also, same error with yii migrate --migrationNamespaces=Da\\User\\Migration.

As I suspected, that pretty much rules out yii2-usuario as being at the root of the problem and brings me back to my original suspicion — the Yii2 2.0.30 upgrade — especially since I never had this problem with usuario before. (All my previous problems had been of my own making.)

Now I'm inclined to downgrade Yii2 and see if a previous version works. I just have to figure out what version to go to.

maxxer commented 4 years ago

Please let me know how it's going

maxxer commented 4 years ago

I just tried creating a new project with Yii 2.0.32 and usuario dev-master and migrations went fine. But I'm on MySQL.

amlopezalonso commented 4 years ago

I ran into this same issue (using MySQL, Yii 2.0.35) when attempting to migrate from a previous Dektrium installation following the steps detailed in:

https://yii2-usuario.readthedocs.io/en/latest/installation/migration-guide-from-dektrium-tools/

As soon as I tried to apply the first proposed migration:

./yii migrate/mark "Da\User\Migration\m000000_000005_add_last_login_at"

I got:

Exception 'yii\base\InvalidConfigException' with message 'Object configuration must be an array containing a "class" or "__class" element.' in /usr/local/share/datos/tmp/desarrollo/tarha/vendor/yiisoft/yii2/BaseYii.php:368 Stack trace:

0 /usr/local/share/datos/tmp/desarrollo/tarha/vendor/yiisoft/yii2/base/Module.php(427): yii\BaseYii::createObject(Array, Array)

1 /usr/local/share/datos/tmp/desarrollo/tarha/vendor/2amigos/yii2-usuario/src/User/Bootstrap.php(44): yii\base\Module->getModule('user')

2 /usr/local/share/datos/tmp/desarrollo/tarha/vendor/yiisoft/yii2/base/Application.php(297): Da\User\Bootstrap->bootstrap(Object(yii\console\Application))

3 /usr/local/share/datos/tmp/desarrollo/tarha/vendor/yiisoft/yii2/base/Application.php(273): yii\base\Application->bootstrap()

4 /usr/local/share/datos/tmp/desarrollo/tarha/vendor/yiisoft/yii2/console/Application.php(124): yii\base\Application->init()

5 /usr/local/share/datos/tmp/desarrollo/tarha/vendor/yiisoft/yii2/base/BaseObject.php(109): yii\console\Application->init()

6 /usr/local/share/datos/tmp/desarrollo/tarha/vendor/yiisoft/yii2/base/Application.php(206): yii\base\BaseObject->__construct(Array)

7 /usr/local/share/datos/tmp/desarrollo/tarha/vendor/yiisoft/yii2/console/Application.php(89): yii\base\Application->__construct(Array)

8 /usr/local/share/datos/tmp/desarrollo/tarha/yii(22): yii\console\Application->__construct(Array)

9 {main}

maxxer commented 4 years ago

As soon as I tried to apply the first proposed migration:

Can you post the application component and module configuration? It seems Yii is unable to fetch the module with id => user

amlopezalonso commented 4 years ago

There you are:

Components:

   /* 'user' => [ // Disabled for Dektrium / yii2-usuario.
        'identityClass' => 'app\models\User',
        'enableAutoLogin' => true,
    ],*/
    'authManager' => [
         'class' => 'yii\rbac\DbManager',
         'defaultRoles' => ['myDefaultRole'],
    ],
    'view' => [
         'theme' => [
             'pathMap' => [
                 '@Da/User/resources/views' => '@app/views/user',
             ],
         ],
     ],
    'db' => require(__DIR__ . '/db.php'),
],

Modules:

'user' => [
          'class' => Da\User\Module::class,
          'administrators'             => ['myadmin'],
          'allowUnconfirmedEmailLogin' => false,
          'enableRegistration'         => false,
          'enableEmailConfirmation'    => true,
          'allowPasswordRecovery'      => true,
          'mailParams' => [
            'fromEmail' => 'info@mydomain',
          ],
          'classMap' => [
            'LoginForm' => 'app\models\LoginForm',
          ],
    ],