Joomla getUser() does not show the updated user data(Joomla getUser() 不显示更新的用户数据)
问题描述
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.
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.
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?
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() 不显示更新的用户数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Joomla getUser() 不显示更新的用户数据
基础教程推荐
- PHP 类:全局变量作为类中的属性 2021-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- 如何替换eregi() 2022-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
