From Joomla! Documentation

< API15:JUser
Revision as of 16:17, 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.


Method to save the JUser object to the database

[Edit Descripton]



Parameter Name Default Value Description
$updateOnly false $updateOnly Save the object only if not a new user


boolean True on success

Defined in



jimport( 'joomla.user.user' );

Source Body

function save( $updateOnly = false )
        // Create the user table object
        $table  =& $this->getTable();
        $this->params = $this->_params->toString();
        $table->username = $table->email;
        // Check and store the object.
        if (!$table->check()) {
                return false;
        // If user is made a Super Admin group and user is NOT a Super Admin
        $my =& JFactory::getUser();
        if ( $this->get('gid') == 25 && $my->get('gid') != 25 )
                // disallow creation of Super Admin by non Super Admin users
                $this->setError(JText::_( 'WARNSUPERADMINCREATE' ));
                return false;
        // If user is made an Admin group and user is NOT a Super Admin
        if ($this->get('gid') == 24 && !($my->get('gid') == 25 || ($this->get('id') == $my->id && $my->get('gid') == 24)))
                // disallow creation of Admin by non Super Admin users
                $this->setError(JText::_( 'WARNSUPERADMINCREATE' ));
                return false;
        //are we creating a new user
        $isnew = !$this->id;
        // If we aren't allowed to create new users return
        if ($isnew && $updateOnly) {
                return true;
        // Get the old user
        $old = new JUser($this->id);
        // Fire the onBeforeStoreUser event.
        JPluginHelper::importPlugin( 'user' );
        $dispatcher =& JDispatcher::getInstance();
        $dispatcher->trigger( 'onBeforeStoreUser', array( $old->getProperties(), $isnew ) );
        //Store the user data in the database
        if (!$result = $table->store()) {
        // Set the id for the JUser object in case we created a new user.
        if (empty($this->id)) {
                $this->id = $table->get( 'id' );
        // Fire the onAftereStoreUser event
        $dispatcher->trigger( 'onAfterStoreUser', array( $this->getProperties(), $isnew, $result, $this->getError() ) );
        return $result;

[Edit See Also] SeeAlso:JUser/save


<CodeExamplesForm />