Skip to content

Instantly share code, notes, and snippets.

@crisu83
Last active December 20, 2015 11:49
Show Gist options
  • Save crisu83/6126696 to your computer and use it in GitHub Desktop.
Save crisu83/6126696 to your computer and use it in GitHub Desktop.
<?php
/**
* Web user component with support for loading the associated model.
*
* You can request attributes on the model object the following way:
* Yii::app()->user->model->username;
*/
class WebUser extends CWebUser
{
/**
* @var string the name of the associated model class.
*/
public $modelClass = 'User';
/**
* Returns the associated model for the logged in user.
* @return CActiveRecord
*/
public function getModel()
{
return !$this->isGuest ? CActiveRecord::model($this->modelClass)->findByPk($this->id) : null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment