JUser/getInstance: Difference between revisions
From Joomla! Documentation
m removing red link to edit, no existant pages |
m preparing for archive only |
||
| Line 66: | Line 66: | ||
===Examples=== | ===Examples=== | ||
=== Code Examples === | |||
<dpl> | <dpl> | ||
noresultsheader=\n | noresultsheader=\n | ||
category=getInstance | category=getInstance | ||
category=JUser | category=JUser | ||
namespace=CodeExample | |||
category=MethodExample | category=MethodExample | ||
include=* | include=* | ||
Latest revision as of 01:15, 25 March 2017
Description
Returns a reference to the global User object, only creating it if it doesn't already exist.
[<! removed edit link to red link >]
<! removed transcluded page call, red link never existed >
Syntax
& getInstance($id=0)
| Parameter Name | Default Value | Description |
|---|---|---|
| $id | 0 | $id The user to load - Can be an integer or string - If string, it is converted to ID automatically. |
Returns
The User object.
Defined in
libraries/joomla/user/user.php
Importing
jimport( 'joomla.user.user' );
Source Body
function &getInstance($id = 0)
{
static $instances;
if (!isset ($instances)) {
$instances = array ();
}
// Find the user id
if(!is_numeric($id))
{
jimport('joomla.user.helper');
if (!$id = JUserHelper::getUserId($id)) {
JError::raiseWarning( 'SOME_ERROR_CODE', 'JUser::_load: User '.$id.' does not exist' );
$retval = false;
return $retval;
}
}
if (empty($instances[$id])) {
$user = new JUser($id);
$instances[$id] = $user;
}
return $instances[$id];
}
[<! removed edit link to red link >] <! removed transcluded page call, red link never existed >
Examples
Code Examples