How to get the user id just register

45 views
Skip to first unread message

Tony Wang

unread,
Sep 25, 2013, 11:31:46 PM9/25/13
to joomla-de...@googlegroups.com
Hi,
I am using joomla2.5,
Now I write a component and want a manager to register an user in the frontend.
I use the JUser object to save the new user to database user table,
but how could I get this new user Id after i saved it immediately as I need this id to do a callback function?

Anyone knows please tell me ,
Thanks in advance!

sovainfo

unread,
Sep 26, 2013, 3:50:28 AM9/26/13
to joomla-de...@googlegroups.com
Use insertid.

Example: plugins/extension/joomla/joomla.php:
        // If it doesn't exist, add it!
        if (!$update_site_id)
        {
            $query->clear()
                ->insert('#__update_sites')
                ->columns(array($db->quoteName('name'), $db->quoteName('type'), $db->quoteName('location'), $db->quoteName('enabled')))
                ->values($db->quote($name) . ', ' . $db->quote($type) . ', ' . $db->quote($location) . ', ' . (int) $enabled);
            $db->setQuery($query);
            if ($db->execute())
            {
                // Link up this extension to the update site
                $update_site_id = $db->insertid();
            }
        }

        // Check if it has an update site id (creation might have faileD)
        if ($update_site_id)
        {


Tony Wang

unread,
Sep 26, 2013, 11:10:47 PM9/26/13
to joomla-de...@googlegroups.com
I found another way,  if we use the object JUser to save user  to database , like this:
 $user = new JUser;
$data = .......;
$user->bind($data);
 $user->save();
$userId = $user->id;
Reply all
Reply to author
Forward
0 new messages