JUser/getInstance
From Joomla! Documentation
< API16:JUser
The "API16" namespace is an archived namespace. This page contains information for a Joomla! version which is no longer supported. It exists only as a historical reference, it will not be improved and its content may be incomplete and/or contain broken links.
Description[edit]
Returns the global User object, only creating it if it doesn't already exist.
Syntax[edit]
static getInstance($identifier=0)
Parameter Name | Default Value | Description |
---|---|---|
$identifier | 0 | $id The user to load - Can be an integer or string - If string, it is converted to ID automatically. |
Returns[edit]
The User object.
Defined in[edit]
libraries/joomla/user/user.php
Importing[edit]
jimport( 'joomla.user.user' );
Source Body[edit]
static function getInstance($identifier = 0)
{
static $instances;
if (!isset ($instances)) {
$instances = array ();
}
// Find the user id
if (!is_numeric($identifier))
{
jimport('joomla.user.helper');
if (!$id = JUserHelper::getUserId($identifier)) {
JError::raiseWarning('SOME_ERROR_CODE', 'JUser::_load: User '.$identifier.' does not exist');
$retval = false;
return $retval;
}
} else {
$id = $identifier;
}
if (empty($instances[$id])) {
$user = new JUser($id);
$instances[$id] = $user;
}
return $instances[$id];
}
Examples[edit]
Code Examples[edit]