Reputation: 740
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.
Upvotes: 1
Views: 730
Reputation: 51
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://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] =>
)
Upvotes: 2