Back to User class

Method load

public bool
load
(mixed $id)
Method to load a User object by user id number
Parameters
  • mixed $id The user id of the user to load
Returns
  • bool True on success
Since
  • 1.7.0
Class: User
Project: Joomla

Method load - Source code

/**
 * Method to load a User object by user id number
 *
 * @param   mixed  $id  The user id of the user to load
 *
 * @return  boolean  True on success
 *
 * @since   1.7.0
 */
public function load($id)
{
    // Create the user table object
    $table = $this->getTable();
    // Load the UserModel object based on the user id or throw a warning.
    if (!$table->load($id)) {
        // Reset to guest user
        $this->guest = 1;
        Log::add(Text::sprintf('JLIB_USER_ERROR_UNABLE_TO_LOAD_USER', $id), Log::WARNING, 'jerror');
        return false;
    }
    /*
     * Set the user parameters using the default XML file.  We might want to
     * extend this in the future to allow for the ability to have custom
     * user parameters, but for right now we'll leave it how it is.
     */
    if ($table->params) {
        $this->_params->loadString($table->params);
    }
    // Assuming all is well at this point let's bind the data
    $this->setProperties($table->getProperties());
    // The user is no longer a guest
    if ($this->id != 0) {
        $this->guest = 0;
    } else {
        $this->guest = 1;
    }
    return true;
}