The code itself is clear enough, I’ve created my UserGroupRule, but the docs don’t specify the file layout for this. If I put my roles in @app/data/rbac.php, the PhpManager tries to overwite that file when it adds its rules and throws a permission denied error when trying to write it. It trying to overwrite itself is a Bad Thing.
Where should this code go? If I put the rules in a console controller, where would I declare my UserGroupRule so Yii finds it?
Everything else seems to be going quite well with Yii2, I’m just hitting this one stumbling block.
You shouldn’t be touching @app/data/rbac.php at all unless you know what you’re doing.
Definitely use a console controller to put the code, but the actual UserGroupRule looks like it should go into @app/rbac/UserGroupRule.php (following the namespace).
After you run it, your rbac.php file should look something like this:
With a bit of trial and error, that got me there. There are a few issues with the advanced application structure, though.
In order to get this to work, I had to create an rbac directory in both the console and frontend directories, and put my UserGroupRole.php class file in both locations. After running the console application to create my rules, I had to then copy the console/data/rbac.php file to frontend/data/rbac.php before it would recognize it.
I would have hoped that I could have used common/rbac/UserGroupRole.php for the UserGroupRule class and common/data/rbac.php for the actual generated rules. I don’t know if this is by design or not.
It is working exactly the way I want it to, though, so I’m happy.