1. morgan_leecy
  2. Support
  3. Thursday, September 07 2017, 04:23 PM
I have been successfully using skeleton.php since I knew if its existence, but for the first time I find myself needed a process that fires on the creation of a new account.

I need to write the users ID to a third party table, but when a new account is created, the user does not have an ID

Am I using this piece of code correctly (this is an example) or is it not possible for skeleton.php to get the user id of a newly created user at the time of registration submission? I can work around this with a two step registration process but would rather just have one for user experience

I have tried both $data['id'] and $user->id;


if ($isNew) {

// Get a db connection.
$db = JFactory::getDbo();

// Create a new query object.
$query = $db->getQuery(true);

$columns = array ('created_by', 'approved', 'published');
$values = array ( $data['id'], '0', '1');

$query
->insert($db->quoteName('#__my_table'))
->columns($db->quoteName($columns))
->values(implode(',', $values));

$db->setQuery($query);

$db->execute();
}


If this is incorrect, how can I use skeleton.php to grab the id from a newly generate user account so I can use it immediately? or does skeleton.php fire before the account is saved so there is no id?

If the account has been created I suppose I could use


$db->execute();
return $db->insertid();


in skeleton.php to grab the ID

Any guidance appreciated
morgan_leecy Accepted Answer
Pro
Of course that code is wrapped in


public function triggerProfileUpdate($user,&$data,$changed,$isNew)
{

//my code

}


cant edit OP to add this line
  1. more than a month ago
  2. Support
  3. # 1
admin Accepted Answer
Admin
Hi,
I have just tried $user->id and works.

my code to test it

public function triggerProfileUpdate($user,&$data,$changed,$isNew)
{
if( $isNew ){
print_r( $user->id ) ;
die();
}
}
  1. more than a month ago
  2. Support
  3. # 2
morgan_leecy Accepted Answer
Pro
Sorry, yes that works fine. I had an error of a different kind which was having a knock on effect. Thanks!
  1. more than a month ago
  2. Support
  3. # 3
morgan_leecy Accepted Answer
Pro
For some reason I cannot accept your answer
  1. more than a month ago
  2. Support
  3. # 4
  • Page :
  • 1


There are no replies made for this post yet.
However, you are not allowed to reply to this post.