JUserHelper/getUserId: Difference between revisions
From Joomla! Documentation
m clean up |
m preparing for archive only |
||
| Line 4: | Line 4: | ||
===Syntax=== | ===Syntax=== | ||
| Line 42: | Line 42: | ||
===Examples=== | ===Examples=== | ||
=== Code Examples === | |||
<dpl> | <dpl> | ||
noresultsheader=\n | noresultsheader=\n | ||
category=getUserId | category=getUserId | ||
category=JUserHelper | category=JUserHelper | ||
namespace=CodeExample | |||
category=MethodExample | category=MethodExample | ||
include=* | include=* | ||
format= ,,, | format= ,,, | ||
</dpl> | </dpl> | ||
Latest revision as of 02:16, 25 March 2017
Description
Returns userid if a user exists
Syntax
static getUserId($username)
| Parameter Name | Default Value | Description |
|---|---|---|
| $username | The username to search on |
Returns
int The user id or 0 if not found
Defined in
libraries/joomla/user/helper.php
Importing
jimport( 'joomla.user.helper' );
Source Body
public static function getUserId($username)
{
// Initialise some variables
$db = & JFactory::getDbo();
$query = 'SELECT id FROM #__users WHERE username = ' . $db->Quote($username);
$db->setQuery($query, 0, 1);
return $db->loadResult();
}
Examples
Code Examples