Skip to Content Skip to Menu

Profile id in code field

5 years 8 months ago #310552 by apurvkolte
Profile id in code field was created by apurvkolte
How to access user id of user viewing the profile and user id of the profile being viewed in the code filed ? I want to use them in php code.

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 48441
  • Thanks: 8275
  • Karma: 1443
5 years 8 months ago #310562 by krileon
Replied by krileon on topic Profile id in code field
CB Code Field allows for substitutions. So to grab the id of the user being displayed use [user_id] and for the user viewing use [cb:userdata field="user_id" user="#me" /]. See the below for further substitution usage information.

www.joomlapolis.com/documentation/279-community-builder/tutorials/18353-using-substitutions-throughout-cb

Note substitutions should always be treated as strings so be sure to enclose it with quotes as needed.


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 or Create an account to join the conversation.

5 years 7 months ago - 5 years 7 months ago #310847 by apurvkolte
Replied by apurvkolte on topic Profile id in code field
I am seeing very odd behavior

$profileUserId = trim('[cb:userdata field="user_id" user="#displayed" /]');
echo $profileUserId; --> This prints 1668, correct user id

echo JFactory::getUser($profileUserId)->id; --> This prints 0 !

Do you see anything wrong above ?

I am referring this www.joomlapolis.com/documentation/279-community-builder/tutorials/18361-obtaining-field-values-through-getfields-api

How to get user if of displayed user in PHP code ?
Last edit: 5 years 7 months ago by apurvkolte.

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 48441
  • Thanks: 8275
  • Karma: 1443
5 years 7 months ago #310854 by krileon
Replied by krileon on topic Profile id in code field

How to get user if of displayed user in PHP code ?

By establishing a CB $user object as instructed in that tutorial, which links to the below tutorial.

www.joomlapolis.com/documentation/279-community-builder/tutorials/18359-establishing-a-cb-user-object


You do not need getFields API access though. It supports substitutions so you can just substitute in the displayed or the viewing users fields.


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 or Create an account to join the conversation.

Moderators: beatnantkrileon
Powered by Kunena Forum