简体   繁体   中英

Joomla override users component model

I'm writing a few plugins to handle user information through an API. There aren't any default processes I've found that could handle this entirely, so I'm using onAfterRoute to override the component model classes.

This is just checking that the component = com_users, and the view = reset or remind:

class plgSystemUseroverride extends JPlugin {

           public function __construct(&$subject, $config = array()) {
              parent::__construct($subject, $config);
          }

          public function onAfterRoute() {
              $app = JFactory::getApplication();
              $input = $app->input;
              if('com_users' == $input->get('option') && 'reset' == $input->get('view') && !$app->isAdmin()) {              
                  require_once(dirname(__FILE__) . '/user/reset.php');
              }

              if('com_users' == $input->get('option') && 'remind' == $input->get('view') && !$app->isAdmin()) {
                  require_once(dirname(__FILE__) . '/user/remind.php');
              }
          }
     }

The files are copied from the users component, and I modified 'remind' for my testing: method processRemindRequest:

$return = JFactory::getMailer()->sendMail($data['mailfrom'], $data['fromname'], $user->email, $subject . " TEST Subject", $body);

The modification works fine if edit the component files directly, but as a plugin the classes are not being overridden.

Nevermind, I figured it out. Removing the view and just checking that the component is 'com_users' is enough. I also set JLoader to register the classes:

  public function onAfterRoute() {
      $app = JFactory::getApplication();
      if('com_users' == JRequest::getCMD('option') && !$app->isAdmin()) {       
          JLoader::register('UsersModelReset', dirname(__FILE__) . '/user/reset.php');
          JLoader::register('UsersModelRemind', dirname(__FILE__) . '/user/remind.php');
      }
  }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM