Skip to content

Instantly share code, notes, and snippets.

@alanwillms
Created March 7, 2014 20:49
Show Gist options
  • Save alanwillms/9419795 to your computer and use it in GitHub Desktop.
Save alanwillms/9419795 to your computer and use it in GitHub Desktop.
<?php
class HWebUser extends CWebUser
{
/**
* @var User
*/
protected $_model;
/**
* @return void
*/
public function init()
{
parent::init();
$this->assignRoles();
}
/**
* @return User|null
*/
public function getModel()
{
if ($this->_model === null) {
$this->_model = User::model()->findByPk(intval($this->id));
}
return $this->_model;
}
/**
* @return void
*/
protected function assignRoles()
{
$auth = Yii::app()->authManager;
$role = ($this->id == 1) ? 'owner' : false;
if ($role && !$auth->isAssigned($role, $this->id)) {
$auth->assign($role, $this->id);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment