Page 1 of 1

JRequest::getVar() depreciated, how works the alternative JFactory::getUser()?

Posted: Mon Feb 05, 2018 1:52 pm
by Barney2103
I use RSFormPro to get data to and from the database. With the following code in a RSFormPro field I can retrieve the specific custom fields (phonenumber of user) for a specific user:

//<code>
$key_id_user=JRequest::getVar();
$customFieldExactName = 'phonenumber';
$customFields = FieldsHelper::getFields('com_users.user', JFactory::getUser($key_id_user), true);
foreach($customFields as $field){
if($field->name == $customFieldExactName){
//return $field->value;
$tmp = $field->value;
$tmp = str_replace(',', "\n", $tmp);
return $tmp;
}
}
//</code>

However I get the message that 'JRequest::getVar()' is depreciated in Joomla 3.8.4. Instead I should use 'JFactory::getUser();' or Jinput. However when I use '$key_id_user=JFactory::getUser();' in the above mentioned example I get no results. Can anyone enlighten me in the use of JInput of JFactory?

Thanks in advance.

Re: JRequest::getVar() depreciated, how works the alternative JFactory::getUser()?

Posted: Tue Feb 06, 2018 2:30 pm
by toivo
You can refer to the attributes of the current user object:

Code: Select all

$user	= JFactory::getUser();
$id		= $user->id;
$name	= $user->name;
$email	= $user->email;
This will also work:

Code: Select all

$id		= JFactory::getUser()->id;