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

For Joomla! 3.x Coding related discussions, please use: http://groups.google.com/group/joomla-dev-general

Moderator: ooffick

Forum rules
Please use the mailing list here: http://groups.google.com/group/joomla-dev-general rather than this forum.
Barney2103
Joomla! Apprentice
Joomla! Apprentice
Posts: 6
Joined: Thu Jun 22, 2017 12:10 pm

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

Postby Barney2103 » Mon Feb 05, 2018 1:52 pm

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.
Last edited by toivo on Mon Feb 05, 2018 2:18 pm, edited 1 time in total.
Reason: mod note: moved to 3.x Coding

User avatar
toivo
Joomla! Exemplar
Joomla! Exemplar
Posts: 9253
Joined: Thu Feb 15, 2007 5:48 am
Location: Nottingham, UK
Contact:

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

Postby toivo » Tue Feb 06, 2018 2:30 pm

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;
Toivo Talikka, Global Moderator
my first programs were assembled and run in 16KB :)
troubleshooting smtp and other articles https://talikka.com/joomla


Return to “Joomla! 3.x Coding”

Who is online

Users browsing this forum: No registered users and 1 guest