API16:JTableUser/load
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
Method to load a user, user groups, and any other necessary data from the database so that it can be bound to the user object.
Syntax
load($userId=null)
| Parameter Name | Default Value | Description |
|---|---|---|
| $userId | null | $userId An optional user id. |
Returns
boolean True on success, false on failure.
Defined in
libraries/joomla/database/table/user.php
Importing
jimport( 'joomla.database.table.user' );
Source Body
function load($userId = null) { // Get the id to load. if ($userId !== null) { $this->id = $userId; } else { $userId = $this->id; } // Check for a valid id to load. if ($userId === null) { return false; } // Reset the table. $this->reset(); // Load the user data. $this->_db->setQuery( 'SELECT *' . ' FROM #__users' . ' WHERE id = '.(int) $userId ); $data = (array) $this->_db->loadAssoc(); // Check for an error message. if ($this->_db->getErrorNum()) { $this->setError($this->_db->getErrorMsg()); return false; } if(!count($data)) { return false; } // Bind the data to the table. $return = $this->bind($data); if ($return !== false) { // Load the user groups. $this->_db->setQuery( 'SELECT g.id, g.title' . ' FROM #__usergroups AS g' . ' JOIN #__user_usergroup_map AS m ON m.group_id = g.id' . ' WHERE m.user_id = '.(int) $userId ); $result = $this->_db->loadObjectList(); $groups = array(); // Check for an error message. if ($this->_db->getErrorNum()) { $this->setError($this->_db->getErrorMsg()); return false; } // Create an array of groups. for ($i = 0, $n = count($result); $i < $n; $i++) { $groups[$result[$i]->id] = $result[$i]->title; } // Add the groups to the user data. $this->groups = $groups; } return $return; }
[Edit See Also] SeeAlso:JTableUser/load
Examples
<CodeExamplesForm />
