Creator Name

More
8 years 10 months ago #87023 by Tuan Pham Ngoc
Replied by Tuan Pham Ngoc on topic Creator Name
Try something like this (I don't have Easy Profile installed on my computer to check)
Code:
$db = JFactory::getDbo(); $query = $db->getQuery(true); $query->select('*') ->from('#__jsn_users') ->where('id=' . $item->created_by); $db->setQuery($query); $profile = $db->loadObject(); if ($profile) { echo $profile->custom_lastname; }

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

  • Antonello Mancuso
  • Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
8 years 10 months ago #87028 by Antonello Mancuso
Replied by Antonello Mancuso on topic Creator Name
It seems I have an error feeding JsnHelper::getUser with $author_id
If I write:
Code:
$surname=JsnHelper::getUser(158)->get('custom_lastname'); //retrieve custom last_name field
it works like a charm!
Instead... if I put inside getUser $author_id:
Code:
$surname=JsnHelper::getUser("$author_id")->get('custom_lastname'); //retrieve custom last_name field
it doesn't work.
Writing on Easy Profile support, they told me that:
"function is $user->getValue not $user->get"
But I haven't understand if I have to apply this to $author_id:
Code:
$author_id=$author->getValue('id'); // get author id
or later to JsnHelper::getUser.
I'll do some trials... if I cannot get the solution, I'll work on your DB get query code.

Eng. Antonello Mancuso

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

  • Antonello Mancuso
  • Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
8 years 10 months ago #87032 by Antonello Mancuso
Replied by Antonello Mancuso on topic Creator Name
The problem is here:
Code:
$author= JFactory::getUser($item->created_by); //get 'object' author of the event $author_id=$author->get('id'); //<-this should give me author ID
If I simply print:
Code:
echo ("Author ID is: ".$author_id);
I get:
Author ID is: 158.
So, it's working!!
But this point break the code (page is not loaded at all):
Code:
$surname=JsnHelper::getUser("$author_id")->get('custom_lastname'); //retrieve custom last_name field
I tried to put $author_id with "", or '' or without quotes, but I always get the page break!
Mmmm.. I'm getting angry :angry: :angry: :dry:

Eng. Antonello Mancuso

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

  • Antonello Mancuso
  • Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
8 years 10 months ago #87034 by Antonello Mancuso
Replied by Antonello Mancuso on topic Creator Name
OK, solved!
The right code is:
Code:
$surname=JsnHelper::getUser($author_id)->get('custom_lastname'); //retrieve custom last_name field
However, I noticed only now that $item->created_by gives me immediately author ID, so also:
Code:
$surname=JsnHelper::getUser($item->created_by)->get('custom_lastname'); //retrieve custom last_name field
works pretty good.
Thanks to everybody and let's mark this topic as SOLVED!!

Eng. Antonello Mancuso

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

Moderators: Tuan Pham Ngoc