/rbac/items.php): Failed to open stream: No such file or directory


After following this Guide Security: Authorization | The Definitive Guide to Yii 2.0 | Yii PHP Framework
I dont know what i did wrong but now whenever i want to ad a role or permission it gives me 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)

So i went looking for the problem and found.

But whenever i change those directions, it gives me the same error

PHP Warning – yii\base\ErrorException

I don’t even know why it keeps searching in backend then.
My repository is GitHub - DikkiX/Schoolproject
Any of u know the solution to this??? i need help Asap!!

@DikkiX A happy new year!! How are you doing?

Well, I’m pretty sure that what I’m going to say is not what you want. But I think it’s time for you to start your project once again from scratch. Abondon the current disordered project and start a brand new one. And …

  1. Don’t try to use any extension. Use only the vanilla Yii.
  2. Don’t try to do 2 or more things at a time. Do it step by step.
  3. Try to read the Guide, at least twice.

As a matter of fact, it’s the fastest way. Don’t make haste, my friend.


I once suggested you to consider using Yii 2 Usario Extension, but that was my mistake. The extension is too old to use in today’s projects, mainly because it doesn’t support the newer bootstrap. I’m very sorry for it.

hi, i would love to do that but my deadline is within 2 weeks. cant switch up anymore adter showing all i got :confused: this is an schoolproject. and unfortunate my teammates didn’t do anything.

I only need the rbac fixed and then im mostly done

The two very obvious questions: Does the directory exist? Is it writable by the web server process?

I went thru everything and can’t see that i needed to create an rbac directory. since the composer did it already in my Vendor.

Now i see this and don’t know how to call it and im confused.
I tried calling it different than on the screenshot but all resulted in not being found.
If u have time maybe u know the solution or can find it in my repository?

Well, I tried to help. You should read the error message again. Don’t get it? Read it a couple of more times.

I’ve got your situation.

I think you should write down what you have done so far. What project template have you adopted? (yii2-app-advanced, I think). What extensions are you using? And what problems do you have now?

No, I won’t look into your repository. Never. Please don’t ask me (or anyone) to write code for you. It’s not a fair thing to do for a student.

You can do it in 2 weeks, if you don’t make haste. Take a little time to review your project.

In yii2-app-advanced, the front-end and the back-end are different 2 applications.

In the front-end '@app/rbac' refers to 'C:\xampp\htdocs\Schoolproject\frontend\rbac', but in the back-end it is 'C:\xampp\htdocs\Schoolproject\backend\rbac'.
So I think that you have setup the RBAC for the front-end successfully, but not for the back-end.

If you want to share the RBAC files in the both ends, consider setup them in '@common\rbac' instead.

didn’t need someone to code it for me, just to check it.

But i fixed it.

1 Like