Joomla getUser()不显示更新的用户数据 [英] Joomla getUser() does not show the updated user data

查看:78
本文介绍了Joomla getUser()不显示更新的用户数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的代码允许我在用户的Joomla个人资料的个人资料页面中显示用户的姓名.鉴于我已经覆盖了模板以获取所需的外观和感觉.

Below code allows me to show the user's name in the profile page of the Joomla profile of a user. Given that I have overridden the template to get the look and feel I want.

$user =& JFactory::getUser();

if (!$user->guest) {
  echo 'You are logged in as:<br />';
  echo 'Real name: ' . $user->name . '';
}

我的问题是我允许用户更新他或她的个人资料.在他更新了他的名字之后,数据库会正确更新,但是它不会在个人资料页面中显示更新的名字.

My problem is I allow user to update his or her profile. After he updates the his name, database is updated correctly but it does not show the updated name in the profile page.

当我浏览Joomla文档时,我发现用户数据存储在会话(JFactory :: getUser())中.如果我print_r($_SESSION)我可以看到用户数据对象.另外,如果我注销,然后再次登录,配置文件页面上将显示更新的名称.

When I go through Joomla docs I found out that user data is stored in the session(JFactory::getUser()). If I print_r($_SESSION) I can see the user data object. Also If I log out then log in again updated name is shown on the profile page.

数据更新后,如何在配置文件页面中显示更新详细信息?有没有一种方法可以在Joomla会话中更新会话数据,而不是手动执行?

How can I show the update details in the profile page once the data has been updated? Is there a way to update the session data in the Joomla session rather than manually doing it?

推荐答案

您应该使用JSession为用户的当前会话设置新数据

you should use JSession to set new data for your user's current session

        $user = JFactory::getUser();
        $session = JFactory::getSession();
        $session->set('user', new JUser($user->id));
        //new data for your user after the update
        $user = JFactory::getUser();
        print_r($user);

这篇关于Joomla getUser()不显示更新的用户数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆