Create role rbac

Hi after installing RBAC , im a bit confused on what to fill here or what im doing wrong.
I have read the Accescontrol and RBAC doc but still clueless.

It keeps saying Rule doesn’t exist so where can i create the rule?

I will show my siteController in backend Behaviors.

If u have an idea please help!

I suppose your’e being confused with RBAC topic.
Read this guide if you have not: Yii2 RBAC Guide

Check the RBAC data storage you use. Find rules storage manualy and make shure you have creaded rule named “Beheerder”. If you use MySql or smth alike - look for auth_rules table.

Also, I suggest you to use migrations for managing your roles state. (Or ConsoleController, just like you can see in the Guide I mentioned) Otherwise you’ll find your app depending on some roles/permissions/rules, than are not presented in your data storage.

The Guide is vague for me.

It shows me that i need to migrate an hierachy with

./yii migrate/create init_rbac

But when i do this it gives me an error.

PS C:\xampp\htdocs\Schoolproject> ./yii migrate/create init_rbac
Exception 'yii\base\InvalidConfigException' with message 'The configuration for the "user" component must contain a "class" element.'

in C:\xampp\htdocs\Schoolproject\vendor\yiisoft\yii2\di\ServiceLocator.php:209

Stack trace:
#0 C:\xampp\htdocs\Schoolproject\vendor\yiisoft\yii2\di\ServiceLocator.php(265): yii\di\ServiceLocator->set('user', Array)
#1 C:\xampp\htdocs\Schoolproject\vendor\yiisoft\yii2\base\Component.php(180): yii\di\ServiceLocator->setComponents(Array)
#2 C:\xampp\htdocs\Schoolproject\vendor\yiisoft\yii2\BaseYii.php(558): yii\base\Component->__set('components', Array)
#3 C:\xampp\htdocs\Schoolproject\vendor\yiisoft\yii2\base\BaseObject.php(107): yii\BaseYii::configure(Object(yii\console\Application), Array) 
#4 C:\xampp\htdocs\Schoolproject\vendor\yiisoft\yii2\base\Application.php(204): yii\base\BaseObject->__construct(Array)
#5 C:\xampp\htdocs\Schoolproject\vendor\yiisoft\yii2\console\Application.php(89): yii\base\Application->__construct(Array)
#6 C:\xampp\htdocs\Schoolproject\yii(22): yii\console\Application->__construct(Array)
#7 {main}

Im really confused right now,
Someone who maybe has time to check thru discord?

Check out you config.php for app. There is ‘user’ key in your ‘components’. It stands for a component initialization via array in your case. You dont have a ‘class’ key inside your ‘user’ array.

Check out this guide for configurations

I followed ur instruction and now i have a new problem.

When creating an role and leaving the Rule empty i get this error.

PHP Warning – yii\base\ErrorException
file_put_contents(C:\xampp\htdocs\Schoolproject\backend/rbac/items.php): Failed to open stream: No such file or directory
1. in C:\xampp\htdocs\Schoolproject\vendor\yiisoft\yii2\rbac\PhpManager.phpat line 799
790791792793794795796797798799800801802803804805806807808    /**
     * Saves the authorization data to a PHP script file.
     * @param array $data the authorization data
     * @param string $file the file path.
     * @see loadFromFile()
    protected function saveToFile($data, $file)
        file_put_contents($file, "<?php\n\nreturn " . VarDumper::export($data) . ";\n", LOCK_EX);
     * Invalidates precompiled script cache (such as OPCache or APC) for the given file.
     * @param string $file the file path.
     * @since 2.0.9
    protected function invalidateScriptCache($file)

You are using PhpManager. It stores data inside items.php file. Looks like it cant locate file with stored data. Checkout PhpManager source file, it has detailed doc on how to use it inside. You can also better unerstand how it works, by diving into source code.

This is one of Yii killer features, tho. (It has detailed comments and docs inside source files.) It’s even better to read source files, than guides sometimes.

Hi, yeah i found out yesterday and fixed it thanks!