3

I have developed a custom component that store some user information in separate tables, I want to store/update user information when user deleted or updated from admin section or front end.

  • In regards to code, show us how you currently are doing it. – Lodder Nov 9 '14 at 10:41
  • Its basic functionality to update the custom component table when user database updated . – lokeshpahal Nov 9 '14 at 14:02
6

You should save your data using a User Plugin - they're very easy to write. An example can be found at Creating a profile plugin, though the example might have more than you need.

The events your code would go into are onUserAfterSave and onUserAfterDelete and are documented at Plugin/Events/User. These events will fire when a user is saved or deleted in the admin or Front-end.

The guts of the plugin would be this:

defined('_JEXEC') or die;
class PlgUserMyPlugin extends JPlugin
{
    protected $app;
    protected $db;

    public function onUserAfterDelete($user, $success, $msg) {
        if (!$success) 
            return false;

        $query = $this->db->getQuery(true)
        ->delete($this->db->quoteName('#__mytable'))
        ->where($this->db->quoteName('userid') . ' = ' . (int) $user['id']);
        $this->db->setQuery($query)->execute();
        return true;
    }

    public function onUserAfterSave($user, $isnew, $success, $msg) {
        if (!$success) 
            return false;

        // Update your table here
        if ($isnew) {
            // New User
        }else{
            // Existing User
        }
    }
}
  • thanks @GDP, I think this is the best way to achieve the required functionality without modifying core files. – lokeshpahal Nov 10 '14 at 4:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.