Difference between revisions of "JUser/getInstance"
From Joomla! Documentation
< API15:JUser
(New page: ===Description===
Returns a reference to the global User object, only creating it if it doesn't already exist.
<span class="editsection" style="font-size:76%;">
<nowiki>[</nowiki>[[De...) |
m (removing red link to edit, no existant pages) |
||
Line 3: | Line 3: | ||
<span class="editsection" style="font-size:76%;"> | <span class="editsection" style="font-size:76%;"> | ||
− | <nowiki>[< | + | <nowiki>[<! removed edit link to red link >]</nowiki> |
</span> | </span> | ||
− | + | <! removed transcluded page call, red link never existed > | |
===Syntax=== | ===Syntax=== | ||
Line 61: | Line 61: | ||
<span class="editsection" style="font-size:76%;"> | <span class="editsection" style="font-size:76%;"> | ||
− | <nowiki>[< | + | <nowiki>[<! removed edit link to red link >]</nowiki> |
</span> | </span> | ||
− | + | <! removed transcluded page call, red link never existed > | |
===Examples=== | ===Examples=== | ||
Line 76: | Line 76: | ||
format= ,,, | format= ,,, | ||
</dpl> | </dpl> | ||
+ | [[Category:Archived pages API15]] |
Revision as of 13:57, 12 May 2013
The "API15" 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 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[edit]
& 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[edit]
The User object.
Defined in[edit]
libraries/joomla/user/user.php
Importing[edit]
jimport( 'joomla.user.user' );
Source Body[edit]
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[edit]
<CodeExamplesForm />