简体   繁体   English

Joomla覆盖用户组件模型

[英]Joomla override users component model

I'm writing a few plugins to handle user information through an API. 我正在编写一些插件来通过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. 我发现没有任何可以完全处理这个的默认进程,所以我使用onAfterRoute来覆盖组件模型类。

This is just checking that the component = com_users, and the view = reset or remind: 这只是检查组件= com_users,以及view = reset或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: 这些文件是从用户组件复制的,我为我的测试修改了'remind':方法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. 删除视图并只检查组件是否为“com_users”就足够了。 I also set JLoader to register the classes: 我还设置JLoader来注册类:

  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');
      }
  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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