sercey
(Sercey)
March 8, 2015, 2:10am
1
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'],
]);
}
sercey
(Sercey)
March 8, 2015, 4:27pm
2
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’
sercey
(Sercey)
March 15, 2015, 5:41am
3
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 !
]);
}