[SOLVED] Get user ID/object of displayed user in PHP

2 years 7 months ago - 2 years 7 months ago #326129 by lousyfool
Hi,

Like others before, I'm also tinkering with the PHP restriction of Advanced Module Manager.

No problem getting a field value of the logged-in user's object who's viewing a profile with
$viewer = CBuser::getMyUserDataInstance();
$fieldValue1 = $viewer->get('CB_FIELD');

And I know that I could get the field value in another user's object (in this case the one whose profile is being displayed) with
$displayed = CBuser::getUserDataInstance(DISPLAYED_USER_ID);
$fieldValue2 = $displayed->get('CB_FIELD');
... if I only knew how to get DISPLAYED_USER_ID ... am obviously a bit thick in the head now.

The briefest hint on this "how to" will be greatly appreciated!

Please Log in to join the conversation.

2 years 7 months ago #326134 by krileon
Replied by krileon on topic Get user ID/object of displayed user in PHP
The displayed user id is only set when directly viewing a user profile. It is not set in any other scenario. It can be accessed with the following, but again it may be NULL or 0 so please be careful with where you use it.

global $_CB_framework;

$displayedUser = $_CB_framework->displayedUser();


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in to join the conversation.

2 years 7 months ago #326145 by lousyfool
Replied by lousyfool on topic Get user ID/object of displayed user in PHP

krileon wrote: The displayed user id is only set when directly viewing a user profile.

Yup, that's what it's about.
And, of course, your code snippet works perfectly well. So, thanks for that!
The following user(s) said Thank You: krileon

Please Log in to join the conversation.

Moderators: beatnantkrileon
Time to create page: 0.308 seconds

Facebook Twitter LinkedIn