我使用的是joomla 2.5,它是默认的"用户配置文件"插件,为joomla的配置文件页面添加了额外的字段。
我也在使用k2,并为我正在工作的视图设置了模板覆盖:
site/templates/template/html/com_k2/category_item.php
在这个视图中,我可以使用成功地"提取"我需要的数据
jimport('joomla.user.helper');
$user = & JFactory::getUser();
$profile = JUserHelper::getProfile($user->id);
echo $profile->profile['fieldname'];
我的问题是。。。如何在不刷新页面的情况下使用jQuery/Javascript更新此字段?不幸的是,没有像这样的joomla函数
JUserHelper::updateProfileField(value,user->id)
这正是我希望在jQuery的.ajax()中使用的……无论如何,我想我可能必须编写一个函数才能做到这一点。。。在这种情况下,我可能不想修改核心的joomla东西(JUserHelper)。。。但也许是我自己的?或者我应该在k2中添加一个可以更新joomla用户配置文件数据的函数吗?
顺便说一句。。。我这样做的全部目的是因为我想在用户配置文件页面中添加一个自定义的"点"字段。。。我只需要一种可靠的阅读方式;从k2 category_item.php视图更新它(我想用ajax)!
谢谢!!!!
您应该编写一个组件来处理ajax调用,或者至少添加一个带有所需任务的控制器,例如,如果您试图获得一些json:
{user:'paul', custom_field_1:'yes and no'}
然后在您的控制器中,即com_your_component/controller.php,您将有一个任务,如"getInfo":
function getInfo() {
// return the json
echo json_encode($myResultArray);
exit; // this will make sure you don't get the template etc.
}
然后将ajax调用发送到:
http://example.com/index.php?option=com_your_component&task=getInfo&format=json