How can I access Profile variables within code?

15 years 3 months ago #87412 by joshuaarcher
I apologize if this is in the wrong thread, but I'm using 1.2 stable, so I thought I'd stick it here. Please direct me to the appropriate group if I am mistaken.

I'm trying to use a profile variable to make some conditional decision trees, and I'm not sure how I am to go about pulling up the profile field. Is there a snipped of code somewhere or an instruction how-to that can help me in this task? The field is custom (I defined it), not a default field.

thanks,

Joshua

Post edited by: joshuaarcher, at: 2009/02/01 04:50

Please Log in to join the conversation.

15 years 3 months ago #87530 by krileon
joshuaarcher wrote:

I apologize if this is in the wrong thread, but I'm using 1.2 stable, so I thought I'd stick it here. Please direct me to the appropriate group if I am mistaken.

I'm trying to use a profile variable to make some conditional decision trees, and I'm not sure how I am to go about pulling up the profile field. Is there a snipped of code somewhere or an instruction how-to that can help me in this task? The field is custom (I defined it), not a default field.

thanks,

Joshua

Post edited by: joshuaarcher, at: 2009/02/01 04:50


Making a custom plugin and wanting to grab a users field value, correct?

User: $user->FIELDNAME
e.g. $user->cb_test


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.

15 years 3 months ago #87537 by joshuaarcher
Replied by joshuaarcher on topic Re:How can I access Profile variables within code?
is the $user field a global, or do I need to create it from some CB function? I couldn't find the value in a dump of the $user field.

As an alternative, I've just pulled it from the DB directly, but there has to be a more elegant solution.

Please Log in to join the conversation.

15 years 3 months ago #87538 by krileon
joshuaarcher wrote:

is the $user field a global, or do I need to create it from some CB function? I couldn't find the value in a dump of the $user field.

As an alternative, I've just pulled it from the DB directly, but there has to be a more elegant solution.


I don't know what you're making.

Component, plugin, module, etc.. I need more details.

If it's code OUTSIDE of CB then you'll need to include the foundation to use CBs functions. Examine login module or other outside CB related components/modules on how to properly do this.

Inside of CB it's a part of the class and function. Review the helloworld plugin in the downloads section or examine existing plugins.


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.

15 years 3 months ago #87540 by joshuaarcher
Replied by joshuaarcher on topic Re:How can I access Profile variables within code?
Sorry, I should have given more details :).

Yes, it's outside of CB - I'm using JUMI to make a conditional redirect based on a field inside of CB.

What code do I need to include to make use of the CB base methods and fields?

Please Log in to join the conversation.

15 years 3 months ago #87544 by krileon
joshuaarcher wrote:

Sorry, I should have given more details :).

Yes, it's outside of CB - I'm using JUMI to make a conditional redirect based on a field inside of CB.

What code do I need to include to make use of the CB base methods and fields?


Well to get the most effiecieny it depends on how many fields and what other functions you want to use.

If all you need is a couple fields from comprofiler table then a query is your best bet for lightweight usage.

If you want access to ALL CBs functions and API then you'd need to include the foundation.

e.g. (this is my own code.. a snippet from one of my components to include and use all CBs API and functions):
[code:1]
//Determines Joomla version
if ( defined( 'JPATH_ADMINISTRATOR' ) ) {
if ( ! file_exists( JPATH_ADMINISTRATOR . '/components/com_comprofiler/plugin.foundation.php' ) ) {
echo 'CB not installed!';
return;
}
$params =& $mainframe->getParams();
include_once( JPATH_ADMINISTRATOR . '/components/com_comprofiler/plugin.foundation.php' );
} else {
if ( ! file_exists( $mainframe->getCfg( 'absolute_path' ) . '/administrator/components/com_comprofiler/plugin.foundation.php' ) ) {
echo 'CB not installed!';
return;
}
$menu = $mainframe->get( 'menu' );
$params = new mosParameters( $menu->params );
include_once( $mainframe->getCfg( 'absolute_path' ) . '/administrator/components/com_comprofiler/plugin.foundation.php' );
}

//Includes core CB files
cbimport( 'cb.database' );
cbimport( 'cb.fields' );
cbimport( 'language.front' ); //Adds CB language file
[/code:1]

You can then use every bit of CBs API and code, etc..

Examine the function "cbimport" inside of plugin.foundation.php for more information on importing different aspects of CB.


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.

Moderators: beatnantkrileon
Time to create page: 0.215 seconds

Facebook Twitter LinkedIn