Yii user types different to 'admin'

Using gii for creating CRUD for an entity, it creates in each controller an accessRules() function, that looks like this:

public function accessRules()
{
    return array(
        array('allow',
            'actions'=>array('create','update'),
            'users'=>array('@'),
        ),
        array('allow', 
            'actions'=>array('admin','delete'),
            'users'=>array('admin'),
        ),
        array('deny',  // deny all users
            'users'=>array('*'),
        ),
    );
}

This basically tells Yii to allow authenticated users to perform 'create' and 'update' actions, and to allow admin users to perform 'admin' and 'delete' actions.

In my application there is another type of user, the HouseAdmin user, with a different role between simple authenticated users and superusers.

With help from here I have created a isHouseAdmin() function that tells if an user is of type HouseAdmin. Now, I need to use that information to make the accessRules() works with 'houseAdmin' users, so I can make rules like:

public function accessRules()
{
    return array(
    array('allow',
        'actions'=>array('index','view'),
        'users'=>array('@'),
        ),
        array('allow',
            'actions'=>array('create','update'),
            'users'=>array('houseAdmin'),
        ),
        array('allow', 
            'actions'=>array('admin','delete'),
            'users'=>array('admin'),
        ),
        array('deny',  // deny all users
            'users'=>array('*'),
        ),
    );
}

How could I do this? Where are those 'admin' and '@' defined so I can add my 'houseAdmin'?

Answers


admin and houseAdmin are the names of the roles. So the should be specified with key roles, but not users:

array('allow',
    'actions' => array('create','update'),
    'roles' => array('houseAdmin'),
),

Read this for more details.


Need Your Help

Java application profiling / tracking

java profiling trace

I have a closed source Java application for which vendor has provided APIs for customization. As I have no other documents, i rely completely on the API's javadoc.