Answer the question
In order to leave comments, you need to log in
How to add a role on dektrium Yii2-user when creating?
From the backend, when creating a new user, it is necessary that he be assigned the user role in the frontend, everything works, I can’t understand why it doesn’t work in the backend.
Here is the main.php part from the backend config
'modules' => [
'user' => [
// following line will restrict access to profile, recovery, registration and settings controllers from backend
'as backend' => 'dektrium\user\filters\BackendFilter',
'controllerMap' => [
'admin' => 'backend\controllers\AdminController',
'registration' => [
'class' => \backend\controllers\AdminController::className(),
'on ' . \backend\controllers\AdminController::EVENT_AFTER_CREATE => function ($event) {
$auth = Yii::$app->authManager;
$role = $auth->getRole('user');
$user = \dektrium\user\models\User::findOne(['username' => $event->form->username]);
$auth->assign($role, $user->id);
}
],
],
],
'user' => [
'class' => 'dektrium\user\Module',
'admins' => ['admin'],
'controllerMap' => [
'admin' => 'backend\controllers\AdminController',
],
],
No action occurs.
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question