如何在joomla 2.5中编辑com_user配置文件模型


how to edit com_user profile model in joomla 2.5

我使用Joomla 2.5开发了一个网站。我必须创建一个自定义的web组件来满足用户的需求。因此,我必须添加更多的功能,并在我的帐户部分显示更多的信息。因此,我不得不在user->profile模型中添加更多的功能。但更新joomla后会被覆盖。

我知道,在更新Joomla时,有模板覆盖机制来防止文件覆盖。

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

因此我需要知道,是否有任何技术可以继承核心配置文件模型和视图类来添加新功能?

谢谢。

您可以在自定义组件用户模型中扩展Joomla的JUser对象,但是有一个选项可以在Joomla中使用配置文件插件(jroot/plugins/user/profile)。

在这里你可以找到一些教程或使用配置文件插件的例子:

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

我刚找到一个论坛主题和例子来扩展juser对象。它适用于joomla 1.5,但如果您创建了一个新组件,则可以将其转换为J2.5:

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

我希望它有帮助

编辑:扩展juser模型的示例:

jroot/管理员/组件/com_customcomp/模型/customuser.php

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

edit2:

jroot/管理员/组件/com_customcomp/模型/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*/}
测试模式:

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

    $model = $this->getModel('Customuser');
    $userData = $model->getData();
    echo '<pre>';
    print_r($userData);
    echo '</pre>';

$用户数据结果:

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] => 
)