you can save the ‘type’ of the user at login using Yii::app()->user->setState(‘isAdmin’, true) and then test its value using ‘visible’=>Yii::app()->user->getState(‘isAdmin’) (or simply Yii::app()->user->isAdmin)
As others have suggested, you may control the visibility of a menu item based on Yii::app()->user->isAdmin. However, before you can do this, you need to determine who is "admin" based on some logic. I handle it this way:
In my user table, I have a numeric userlevel field. I have 3 types of users: regular (userlevel: 0 -4), admin (userlevel >4) and superuser (userlevel >=10 ).
In the authenticate() function of UserIdentity.php, I add the following code to set isAdminUser and isSuperUser:
<?php
class raviCWebUser extends CWebUser
{
public function isAdminUser() {
return $this->getState('isAdminUser');
}
public function isSuperUser() {
return $this->getState('isSuperUser');
}
}
And I also need to tell Yii that I want to use a different CWebUser by including the following in the main configuration file: