1

I have developed a web site using Joomla 2.5. I had to create a custom web component to facilitate user requirement. Therefore I had to add more functions and show more information in my account section. Therefore I had to add more functions in user->profile model. But It will be overwrite after update joomla.

I know, there is template overriding mechanism to prevent files from overwriting when updating Joomla.

http://docs.joomla.org/How_to_override_the_output_from_the_Joomla!_core

Therefore I need to know, is there any technique available to inherit core profile model and view classes to add new functionality?

Thanks.

cha
  • 730
  • 2
  • 12
  • 28
  • I have found a document which describes how to override controller, model and views in joomla!.http://docs.joomla.org/How_to_override_the_component_mvc_from_the_Joomla!_core – cha Aug 05 '14 at 06:58
  • This post also helpful- http://stackoverflow.com/questions/13763539/overriding-joomla-core-component-file – cha Aug 05 '14 at 08:56

1 Answers1

2

you can extend JUser object of Joomla in your custom component user model, but there is an option to use profile plugin in joomla (jroot/plugins/user/profile).

Here you can find some tutorials or example for using profile plugin:

http://library.logicsistemi.it/en/joomla/general-topics/40-joomla-25-extending-users-data-with-custom-fields

http://www.inmotionhosting.com/support/edu/joomla-25/user-profile/copy-user-profile-plugin

I just found a forum topic and example to extending the juser object. It is for joomla 1.5, but if you created a new component, you can translate it to J2.5:

h**p://forum.joomla.org/viewtopic.php?f=304&t=403113#p1703743

I hope it helped

edit: example of extending juser model:

jroot/administrator/components/com_customcomp/models/customuser.php

class customUser extends JUser {
  // here you can override inherited JUser functions
}

edit2:

jroot/administrator/components/com_customcomp/models/customuser.php

defined('_JEXEC') or die('Restricted access');

if (!class_exists('UsersModelProfile'))
 require(JPATH_SITE.DS.'components'.DS.'com_users'.DS.'models'.DS.'profile.php');

//profile.php contains UsersModelProfile class 
//if your component is called com_newcomp and view is called customuser, the new class name sould be: NewcompModelCustomuser 
class NewcompModelCustomuser extends UsersModelProfile {/*anything*/}

test model:

in file jroot/administrator/components/com_customcomp/views/customuser/view.html.php

    $model = $this->getModel('Customuser');
    $userData = $model->getData();

    echo '<pre>';
    print_r($userData);
    echo '</pre>';

$userData results:

JUser Object
(
    [isRoot:protected] => 
    [id] => 0
    [name] => 
    [username] => 
    [email] => 
    [password] => 
    [password_clear] => 
    [usertype] => 
    [block] => 
    [sendEmail] => 0
    [registerDate] => 
    [lastvisitDate] => 
    [activation] => 
    [params] => Array
        (
        )

    [groups] => Array
        (
        )

    [guest] => 1
    [lastResetTime] => 
    [resetCount] => 
    [_params:protected] => JRegistry Object
        (
            [data:protected] => stdClass Object
                (
                )

        )

    [_authGroups:protected] => 
    [_authLevels:protected] => 
    [_authActions:protected] => 
    [_errorMsg:protected] => 
    [_errors:protected] => Array
        (
        )

    [aid] => 0
    [email1] => 
    [email2] => 
)
Gregory
  • 51
  • 5
  • Thanks for reply. Actually I'm showing collected data from my custom component in My account section. Therefore I need to change core profile model to retrieve data. But I think it is unsafe. Because it will be overwritten after update joomla. Is there any solution for this? – cha Jul 31 '14 at 07:47
  • you should create a new custom usermodel, where you extend the existing juser model: class customUser extends JUser { // here you can override inherited JUser functions } – Gregory Jul 31 '14 at 08:33
  • Can I override view and controller also? – cha Jul 31 '14 at 08:36
  • yes you can, but don't forget to require the neccessary file, where the original object is defined. – Gregory Jul 31 '14 at 08:42
  • Thanks Gregory. I will check this. – cha Jul 31 '14 at 08:48
  • I tried to add new model. But it failed. new class - require 'profile.php'; class customUser extends JUser { And tried to call from view - $model = $this->getModel('custom'); Can you tell where did I make mistake? – cha Aug 04 '14 at 11:22
  • Did you try this in joomla 2.5? – cha Aug 04 '14 at 12:37
  • Actually I want to use this in same profile view and need to call these two models. – cha Aug 04 '14 at 12:47
  • I just tried it and it works. The syntax of new model name is important. – Gregory Aug 04 '14 at 13:03
  • I can send you the installable example component, but I'm new to stackoverflow, and I don't know if I can or how I can attach zip files :) – Gregory Aug 04 '14 at 13:20
  • I have tried this. It works for me. But I want to add extra model to com_user and call it from profile view. I tried it. It failed. – cha Aug 05 '14 at 05:01
  • Can you please email me. My email is chamath(dot)gunasekara(at)gmail(dot)com – cha Aug 05 '14 at 05:18
  • I used this way to call model. $actionsModel = & JModel::getInstance('Customuser', 'UsersModel'); Then it works well. I think I need to register model in controller to call getModel() method. – cha Aug 05 '14 at 05:38
  • I have found a document which describes how to override controller, model and views in joomla!.http://docs.joomla.org/How_to_override_the_component_mvc_from_the_Joomla!_core – cha Aug 05 '14 at 06:58