/** * when user login in backend , it should be 'Administrator' or ,'Merchant' */ public static function beforeLogin() { Event::on(\yii\web\User::className(), \yii\web\User::EVENT_BEFORE_LOGIN, function ($event) { $user = $event->identity; $auth = new DbManager(); $auth->init(); $role = $auth->getRolesByUser($user->id); $event->isValid = in_array(current($role)->name, ['Administrator', 'Merchant']); }); }