Quantcast
Channel: Yii Framework Forum
Viewing all articles
Browse latest Browse all 18717

Rbac - How To Check/change Role Of Users

$
0
0
Hey there,

I just started using yii in my first little project. Yesterday I started experimenting with the RBAC-System of yii. I know there are Extensions for that but I want to understand it myself so I decided to use yii only.

I only created 2 roles "User" and "Admin" and assigned them to 2 Users

$auth->createRole('admin','Administrator');
$auth->createRole('user','Benutzer');

$auth->assign('admin',4);
$auth->assign('user',5);


In my Controller I created the following accessrules to see if it works
return array(
            array('allow',
            	'actions' => array('index', 'add'),
            	'roles' => array('admin'),
            ),
            array('deny',
            	'actions' => array(),
            	'users'=>array('*'),
        	),
        );


It works. My Admin can access both actions and my normal User cannot. BUT, how can I see the actual role I assigned to the User? Or how can I get all Users or all Admins at once?

I'm planning to write an Admin Panel where I can change the userroles but I don't know how I can get the actual role a user has.
I know I could save the role in my user Table in an additional column but this could lead to inconsitency of my DB. And the roles are already stored somwhere so I should be able to access this information ;)

Any suggestions?

Viewing all articles
Browse latest Browse all 18717

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>