0

我有 2 个不同的表userorganiser并且我正在尝试为两个用户创建 2 个不同的登录名。

我可以轻松地注册它们并在数据库中获取记录,但是在保存记录后,我在以下代码行中收到错误

if ($user = $model->signup()) {
           if (Yii::$app->getUser()->login($user)) { //yii\web\IdentityInterface error
                return $this->goHome();
            }
        }

以下是我的configuration模块

    'components' => [
    'user' => [
        'identityClass' => 'common\models\User',
        'enableAutoLogin' => true,
        'identityCookie' => [
            'name' => '_frontendOrganiser', // unique for frontend
        ],
    ],
    'users' => [
        'class' => 'yii\web\User',
        'identityClass' => 'common\models\Users',
        'enableAutoLogin' => false,
        'enableSession' => true,
        'identityCookie' => [
            'name' => '_frontendUser', // unique for frontend
        ],
    ],

    'session' => [
        'name' => 'PHPFRONTSESSID',
        'savePath' => sys_get_temp_dir(),
    ],
]

那么我在这里做错了什么?我是否需要创建任何其他接口或其他东西或为不同的模块提供不同的接口?

我必须这样做,因为organiser表使用password_hash技术来登录我的user表来自另一个项目的用户并且他们使用md5技术,所以我必须为两个用户创建单独的模块。

传递给 yii\web\User::login() 的参数 1 必须是 yii\web\IdentityInterface 的实例,给定的 common\models\Users 的实例,在 C:\xampp\htdocs\project\frontend\controllers\SiteController 中调用.php 在第 202 行并定义

确切的错误陈述如上。

4

1 回答 1

0

我认为您的用户模型没有正确实现 Identity 接口。

尝试检查您的数据模型(在您的数据库中),这必须包含接口的所有字段管理托架。

并确保您的用户正确实现了身份接口。并将接口方法与您的模型正确映射..

请参阅此http://www.yiiframework.com/doc-2.0/yii-web-identityinterface.html的界面文档

于 2015-11-11T07:42:31.757 回答