How to reference custom field with PHP?

10 years 2 months ago #7270 by iananderson
Hi,

I have a custom field for Company Name in my user profile. I want to display this Company Name in a table using something like:

<td>
<?php $user = JFactory::getUser($item->created_by); //echo $user->ajax_custom_field->15; ?>
</td>

What is the correct code for ajax_custom_field->15 ?

Thanks

Ian

Please Log in or Create an account to join the conversation.

10 years 2 months ago #7271 by Saka

Please Log in or Create an account to join the conversation.

10 years 2 months ago #7272 by giosto
Unfortunately, I found a serious error to the component!
When I want to access extra fields from a user that is NOT the current one, do not get any extra field.
I checked and all the other normal fields (not extra) are correctly valued.
for example:

1) require the current user: $utente =& JFactory :: getUser ();
There are all my extra fields (example: $utente-> extra is ok)

2) I wonder if the data of another user (by id): $utente = JFactory :: getUser (639);
all the normal fields (example: username, email, etc..) there are, and all the extra fields are NOT valued!

For my needs this is a very serious problem.

Giovanni

Please Log in or Create an account to join the conversation.

10 years 2 months ago #7273 by iananderson

www.sakic.net/forum/ajax-series/using-in...ter/msg7459/#msg7459

Thanks for this info.

But when I follow the instructions I get mixed results.

I am using the code:
<td>
<?php $user = JFactory::getUser($item->created_by); echo $user->extra; ?>
</td>

But it only works when the Super Admin is logged in. For a public user or registered user, the table is blank.

Any help?

Thanks

Please Log in or Create an account to join the conversation.

10 years 2 months ago #7275 by Saka
AJAX Register automatically attaches the extra info only to the current user.
If you want to get extra info for other users you can do something like this:
$user = JFactory::getUser($userid);
plgSystemAJAXRegister::attachExtraFields($user);
print_r($user->extra);

Emir Sakic
www.sakic.net

Please Log in or Create an account to join the conversation.

10 years 2 months ago #7276 by giosto
Very good!
Now it works.
Perhaps it is important to write the documentation for the component.

Thank you.

Please Log in or Create an account to join the conversation.

About us

We provide high quality Joomla components created by a co-founder and original core developer of Joomla. For over a decade, our products have been used by more than 20.000 webmasters around the world.

Stay in touch