Joomla getUser () does not show updated user data

The code below allows me to display the username on the Joomla user profile profile page. Given that I redefined the template to get the look I want.

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

My problem is that I allow the user to update their profile. After it updates its name, the database is updated correctly, but the updated name is not displayed on the profile page.

When I view Joomla documents, I find out that user data is stored in a session (JFactory :: getUser ()). If I print_r($_SESSION) , I can see the user data object. Also, if I log out, then log back in. The updated name is displayed on the profile page.

How to show update data on profile page after updating data? Is there a way to update session data in a Joomla session, rather than manually doing this?

+4
source share
3 answers

you should use JSession to set new data for the current user 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); 
+7
source

I know that in the latest version of Joomla 2.5.9 this is still a problem, and a workaround seems to be added to the component function / com _users / controllers / profile.php edit AFTER the user record has been successfully saved.

 // Get session user object $session = JFactory::getSession(); $tmpUser = $session->get('user'); // Update necessary fields $tmpUser->name = $data['name']; $tmpUser->email = $data['email1']; // Update the session user object $session->set('user', $tmpUser); 

You CANNOT use the previously recommended set ("user", new JUser ($ user-> id)); because you do not save all the data found in the user object of the Joomla session (access permissions).

+1
source

This is actually more complicated than it sounds, and essentially you need to get them to be redefined. This is due to the messy interaction of JUser and JSession.

0
source

All Articles