4

Is it possible to override the com_users save function?

This is what I tried so far...

<?php
echo JPATH_SITE.'/components/com_users/models/profile.php';
require_once JPATH_SITE.'/components/com_users/models/profile.php';

class NbrealUsersModelProfile extends UsersModelProfile{
    public function save($data){
        die("it works");
    }
}
?>

I added this on the template index file..

3

This docs page should help you with this:

https://docs.joomla.org/How_to_override_the_component_mvc_from_the_Joomla!_core

NOTE: this does not work on its own, instead you need to create a plugin for your overridden controller:

There may be times when you need to override the Joomla! MVC Component to add new functionality or to completely customise the component. The MVC component can be completely overridden by using the same class names that are used in the component. This is achieved by loading a system plugin before the component is dispatched by the application.

You can create your own plugin to do this.

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

 public function onAfterRoute() {
     $app = JFactory::getApplication();
     if('com_content' == JRequest::getCMD('option') && !$app->isAdmin()) {
         require_once(dirname(__FILE__) . '/comcontentoverride/my_content_controller.php');
     }
 } 

}

in your case you need to modify it to something like

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

 public function onAfterRoute() {
     $app = JFactory::getApplication();
     if('com_user' == JRequest::getCMD('option') && !$app->isAdmin()) {
         require_once(dirname(__FILE__) . '/../../templates/{template_name}/code/com_users/profile.php');
     }
 } 
}
  • Can you give me a working example, including the file you used to make the override? I need to override the profile.php model, function save() – miguelmpn Sep 14 '15 at 10:29
  • I have this code on the folder /templates/{template_name}/code/com_users/profile.php <?php defined('_JEXEC') or die; use Joomla\Registry\Registry; class UsersModelProfile extends JModelForm{ protected $data; public function save($data){ die; } } – miguelmpn Sep 15 '15 at 9:08
  • I also tried to require_once the original file and extending the class... – miguelmpn Sep 15 '15 at 9:09
  • You need to add and import a new plugin. See my expanded answer – jdog Sep 16 '15 at 22:50

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.