我正在使用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 stuff(JUserHelper)......但也许是我自己的?或者我应该向k2添加一个可以更新joomla用户配置文件数据的函数吗?
btw ...我这样做的全部意义在于我想在用户个人资料页面添加一个自定义的“积分”字段......我只需要一种可靠的阅读方式。从k2 category_item.php视图更新它(我认为是ajax)!
谢谢!!!!
答案 0 :(得分:0)
你应该编写一个组件来处理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