Revision #2 has been created by AndroideLP on Apr 3, 2018, 11:31:58 PM with the memo:
error in code tag
« previous (#1) next (#3) »
Changes
Title
unchanged
How to login from different tables in Yii2
Category
unchanged
How-tos
Yii version
unchanged
2.0
Tags
changed
authentication,login,different table name,multiple login
Content
changed
[...]
Yii2 utilizes by default UserIdentity configured in config/web.php for connection, this object appy one table to authentication ('identityClass' => 'app\painel\models\User'). How to authentication from diferent tables?
Solution:
Create instances in web.php to uses UserIdentify.
eg:
```php
$user = \Yii::$app->user;
$school = \Yii::$app->school;
$teacher = \Yii::$app->teacher;
```
My config/web.php
```php
'user' => [
'class'=>'yii\web\User',[...]
]
],
```
Note for each there is a identifyClass and one view login.
Now, we need to create the models:
```php
namespace app\models;
use Yii;[...]
//// to continues....
```
Model scholl:
```php
namespace app\models;
use Yii;
// My School[...]
return '{{%schoolUser}}';
}
//// to continues....
```
Model Teacher:
```php
namespace app\models;
use Yii;
// My School[...]
```php
//behaviors of the school
public function behaviors()
{[...]
];
}
```
To use login:
```php
//school
\Yii::$app->scholl->login($model, $this->rememberMe ? 3600*24*30 : 0);[...]