Answer the question
In order to leave comments, you need to log in
How to implement rbac dbmanager in yii2-advanced?
In basic, it turned out to implement RBAC. Today I started to study advanced and I can't implement RBAC.
How I do:
Step 1: Registered in /common/config/main.php
'components' => [
'authManager' => [
'class' => 'yii\rbac\DbManager',
],
],
php yii migrate [email protected]/rbac/migrations/
<?php
namespace yii\console\controllers;
use Yii;
use yii\console\Controller;
use common\models\User;
class RbacController extends Controller {
public function actionInit() {
$auth = Yii::$app->authManager;
// Удаляем старые данные из бд
$auth->removeAll();
// Создадим роли админа и пользователя
$admin = $auth->createRole('admin');
$user = $auth->createRole('user');
// запишем их в БД
$auth->add($admin);
$auth->add($user);
// Назначаем роль admin пользователю с ID 1
$auth->assign($admin, 1);
}
Exception 'yii\base'UnkownClassException' with message 'Unable to find 'console\controllers\RbacController.php' in file: D:\domains\yii2/console/controllers\RbacController.php. Namespace missing?'
in D:\Openserver\domains\yii2\vendor\yiisoft\yii\BaseYii.php:291
Answer the question
In order to leave comments, you need to log in
You have a controller in the console/commands namespace, but you need it to be in console/controllers.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question