[solved]Seperate User Instance in Module

Hi,

I have two different user table(editors and users) in database. User table as you know and the Editor table is just using in module.

I use this way to seperating user instances from between module and main application in Yii 1.1.

But I can’t find a way in yii 2. I try extend yii\web\User and I change user class in module but same results. If I login in module, same User instance is accessible from out of module and anywhere.

My module init like this:




public function init()

    {

        parent::init();


        \Yii::$app->set('user', [

            'class' => 'app\modules\yonetim\components\yonetimUser',

            'identityClass' => 'app\models\Editor',

            'enableAutoLogin' => true,

            'loginUrl' => ['yonetim/default/login'],

        ]);


    }



Also I try add a component in main config like this




'components' => [

    'user' => [

        'identityClass' => 'app\models\User',

        'enableAutoLogin' => true,

    ],

    'editor' => [

        'class' => 'yii\web\User',

        'identityClass' => 'app\models\Editor',

        'enableAutoLogin' => true,

    ],

],



but this time I don’t use Yii::$app->editor instead of Yii::$app->user. And authorization roles(like @) working with ‘user’, not ‘editor’

I found a way for different login instance. Yii2 using session id param for authentication. So we need the change it.

In your modules\module_name\module_name.php file should be looks like this:




public function init()

{

    parent::init();


    Yii::$app->set('user', [

        'class' => 'yii\web\User',

        'identityClass' => 'app\models\Editor',

        'enableAutoLogin' => false,

        'loginUrl' => ['yonetim/default/login'],

        'identityCookie' => ['name' => 'editor', 'httpOnly' => true],

        'idParam' => 'editor_id', //this is important !

    ]);

}