Skip to content

Instantly share code, notes, and snippets.

Created November 14, 2014 09:45
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
* get user roles
public function getRoles(){
$roles = array();
$sql = sprintf('select itemname from %s where userid = %d', Yii::app()->authManager->assignmentTable, Yii::app()->user->id);
//cache dependency
$dependency = new CDbCacheDependency('SELECT MAX(lastModified) FROM ' . Yii::app()->authManager->assignmentTable);
foreach (array_values(Yii::app()->db->cache(86400, $dependency)->createCommand($sql)->queryAll()) as $row)
$roles[] = $row['itemname'];
//add default roles to user if has no role
if (empty($roles))
$roles[] = Yii::app()->user->isGuest ? 'guest' : 'authenticated';
return $roles;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment