API15:JUser/getInstance
From Joomla! Documentation
This Namespace has been archived - Please Do Not Edit or Create Pages in this namespace. Pages contain information for a Joomla! version which is no longer supported. It exists only as a historical reference, will not be improved and its content may be incomplete.
Contents |
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
<CodeExamplesForm />
