配置Yii2中的多个用户身份 [英] multiple user identity in config Yii2

查看:403
本文介绍了配置Yii2中的多个用户身份的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个具有两个不同注册的网站,并且我有2个不同的表,Im使用RbacDB,并且在组件部分的Web配置中,我具有用户配置,根据此我想知道如何使用2个不同的表配置文件中的字段?

I developing a site with two different registrations, and I have 2 different table, Im using RbacDB, and in the web config in the components section I have user configuration, according to this I want to know how I can use 2 different fields in the config file?

config:

'components' => [
    'request' => [
        // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
        'cookieValidationKey' => '213h2i3121h12osiajls',
    ],
    'cache' => [
        'class' => 'yii\caching\FileCache',
    ],
    'user' => [
        'identityClass' => 'app\models\User',
        'enableAutoLogin' => true,
    ],
    // Here after user I need to add another config user-two
    'user-two' => [
        'identityClass' => 'app\models\SecondUser',
        'enableAutoLogin' => true,
    ],

当我这样做时,显示此错误 在此处输入图片描述

when I do it, shows this error enter image description here

谢谢!

推荐答案

尝试在用户两个组件中设置类属性:

Try to set a class property in the user-two component:

'user-two' => [
    'class' => 'yii\web\User'
    'identityClass' => 'app\models\SecondUser',
    'enableAutoLogin' => true,
],

或创建从yii \ web \ User类继承的新类,并进行如下设置:

or create new class inherited from the yii\web\User class and set like this:

'user-two' => [
    'class' => 'app\models\NewClassInheritedFromUserClass'
    ....
]

也许这会对您有所帮助.

Maybe this will help you.

这篇关于配置Yii2中的多个用户身份的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆