Using RBAC
RBAC is the most powerful access control method available in Yii. It is described in the guide, but since it is rather complex and powerful, it is not so easy to understand how it actually works without getting under the hood a little.
In this recipe, we will take the roles hierarchy from the definitive guide, import it, and explain what is happening internally.
Getting ready
Create a fresh web application by using
yiic webapp.Create a MySQL database and configure it.
Import SQL from
framework/web/auth/schema-mysql.sql.Configure the
authManagercomponent in yourprotected/config/main.phpas follows:return array( 'components'=>array( … 'authManager'=>array( 'class'=>'CDbAuthManager', 'connectionID'=>'db', ), ), … );Add additional roles to
protected/components/UserIdentity.php. Theusersarray should look like the following:$users=array( // username => password 'demo'=>'demo', 'admin'=>'admin', 'readerA'=>'123', 'authorB'...