I’ve been trying to write some RBAC using the CPhpAuthManager default. I added a very simple protected/data/auth.php file:
$authManager = Yii::app()->authManager;
$authManager->createOperation('createThingy', 'create a thingy');
However, when I call Yii::app()->user->checkAccess(…), I get the following fatal error:
Fatal error: Call to a member function createOperation() on a non-object in C:\xampp\htdocs\myproject\protected\data\auth.php on line 3.
which means that Yii:app()->authManager returns a null value (I double-checked this via a var_dump call and it was indeed null). Now, I’ve tried this both with and without declaring an AuthManager component in the main config. I thought that by default Yii uses the CPhpAuthManager, so the call should work regardless.
Anyone encountered this before or know what I’m missing?
You are getting a recursive call to a file and this will eventually cause the system to fall over. The auth manager in the application is using your file for authorisation information. You however are calling the auth manager from inside this file so when you include it into the auth manager for the application, it calls back to itself and so-on.
Create an empty auth file and use the functions on the CPhpAuthManager to read and write to this file, you will make sure the format of the code is correct and it will not recurse.