for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* Represents the currently authenticated user
*
* @author Sam Stenvall <[email protected]>
* @copyright Copyright © Sam Stenvall 2013-
* @license https://www.gnu.org/licenses/gpl.html The GNU General Public License v3.0
*/
class WebUser extends CWebUser
{
* @var User the user model
private $_model;
* @return string the username of the current user
public function getName()
$user = $this->loadUser();
return $user !== null ? $user->username : 'guest';
}
* Returns the user's role
* @return string
public function getRole()
return $user !== null ? $user->role : User::ROLE_NONE;
* Loads the user model
* @return User the user
protected function loadUser()
if ($this->_model === null)
if ($this->id !== null)
$this->_model = User::model()->findByPk($this->id);
return $this->_model;