Reputation: 8424
$app = JFactory::getApplication();
$app->setUserState('com_users.reset.user', $user->id);
$userId = $app->getUserState('com_users.reset.user');
This
echo $userId;
will print nothing
echo $user->id;
will print the user id correctly.
How can I setUserState ?
I found that in libraries/joomla/application/application.php the function getUserState is failing when if (!is_null($registry)) and returns null
public function setUserState($key, $value)
{
$session = JFactory::getSession();
$registry = $session->get('registry');
if (!is_null($registry))
{
return $registry->set($key, $value);
}
return null;
}
Upvotes: 1
Views: 1197
Reputation: 8424
I found a solution. I am not sure what caused this. But if for a reason the "registry" session variable is not working then you can initialize it like this. And it works.
$session = JFactory::getSession();
$session->set('registry', new JRegistry('session'));
Upvotes: 1