Skip to content

Instantly share code, notes, and snippets.

@enyachoke
Created September 14, 2012 12:39
Show Gist options
  • Save enyachoke/3721687 to your computer and use it in GitHub Desktop.
Save enyachoke/3721687 to your computer and use it in GitHub Desktop.
A three level user access control without rbac.Yii framework
<?php
/**
* Created by JetBrains PhpStorm.
* User: ubeergeek
* Date: 9/12/12
* Time: 12:34 PM
* To change this template use File | Settings | File Templates.
*/
class WebUser extends CWebUser{
private $_user;
//is the user an admin ?
function getIsAdmin(){
return ( $this->user && $this->user->accessLevel == User::LEVEL_ADMIN );
}
//is the user a provider ?
function getIsProvider(){
return ( $this->user && $this->user->accessLevel == User::LEVEL_PROVIDER );
}
//is the user an Agent?
function getIsAgent(){
return ( $this->user && $this->user->accessLevel == User::LEVEL_AGENT );
}
//get the logged user
function getUser(){
if( $this->isGuest )
return;
if( $this->_user === null ){
$this->_user = User::model()->findByPk( $this->id );
}
return $this->_user;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment