Actions

API16

JUser/getInstance

From Joomla! Documentation

< API16:JUser
Revision as of 17:43, 22 March 2010 by Doxiki (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Replacement filing cabinet.png
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 the global User object, only creating it if it doesn't already exist.

[Edit Descripton]

Description:JUser/getInstance

Syntax

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

The User object. 

Defined in

libraries/joomla/user/user.php

Importing

jimport( 'joomla.user.user' );

Source Body

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];
}

[Edit See Also] SeeAlso:JUser/getInstance

Examples

<CodeExamplesForm />