[SOLVED] Loading API externally in component issues

13 years 2 months ago - 13 years 2 months ago #154348 by sfraise
Hi, I want to build a component that uses an ajax function to retrieve cb field values through a php file located in the component folder. The problem I'm having though is that I keep getting an error that the functions in cb.core.php are on non objects.

Right now I'm just testing with a simple echo after the cb api call, Here's my php file info:
<?php global $_CB_framework, $_CB_database, $ueConfig, $mainframe, $_SERVER;
$user_id = cbGetParam( $_REQUEST, 'user', null );
$myId			=	$_CB_framework->myId();
$cbUser			=&	CBuser::getInstance( $myId );
 
if ( ! $cbUser ) {
	$cbUser		=&	CBuser::getInstance( null );
}
 
$user			=	$cbUser->getUserData();
if ( ! $user ) {
	return;
}
$query = "SELECT username FROM jos_users WHERE id = ". (int) 
$_CB_framework->myId();
$_CB_database->setQuery( $query );
$username = htmlspecialchars( cbUnHtmlspecialchars( $_CB_database->loadResult() ) );
if ( defined( 'JPATH_ADMINISTRATOR' ) ) {
	if ( ! file_exists( JPATH_ADMINISTRATOR . '/components/com_comprofiler/plugin.foundation.php' ) ) {
		echo 'CB not installed!';
		return;
	}
 
	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;
	}
 
	include_once( $mainframe->getCfg( 'absolute_path' ) . '/administrator/components/com_comprofiler/plugin.foundation.php' );
}
cbimport( 'cb.database' );
cbimport( 'cb.html' );
cbimport( 'language.front' );
cbimport( 'cb.plugins' );
cbimport( 'cb.snoopy' );
 
function getField( $fieldName, $defaultValue = null, $output = 'html', $formatting = 'none', $reason = 'profile', $list_compare_types = 0 ) {};
$cb_activities	=	$cbUser->getField( 'cb_activities', null, 'html', 'none', 'list' );
$cb_interests	=	$cbUser->getField( 'cb_interests', null, 'html', 'none', 'list' );
$cb_music	=	$cbUser->getField( 'cb_music', null, 'html', 'none', 'list' );
$cb_books	=	$cbUser->getField( 'cb_books', null, 'html', 'none', 'list' );
$cb_movies	=	$cbUser->getField( 'cb_movies', null, 'html', 'none', 'list' );
$cb_tv	=	$cbUser->getField( 'cb_tv', null, 'html', 'none', 'list' );
?>

<?php
echo $username;
?>

Any idea at first glance why the API isn't working correctly here?
I also tried stripping the file down to just the basic call for the api externally exactly as listed on Krileon's api page and I still get the non object errors.

Please Log in to join the conversation.

13 years 2 months ago #154410 by krileon
Please review the below tutorial for including CB API externally.

www.allmysocials.com/tutorials/item/231-include-api-externally

Once done please review the tutorial concerning building of CB user object below.

www.allmysocials.com/tutorials/item/232-establishing-user-object


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.

13 years 2 months ago - 13 years 2 months ago #154462 by sfraise
Ok, I seem to have figured it out, although not 100% sure why lol.
I compared my code to the code in the tutorials again and moved the part where I define the user object below the part that loads the api. I also added all of the cb imports, and had to put a require once to the object.php, observable.php and config.php files in Joomla.
The last thing I had to do was disable the cb wall as I kept getting a Jplugin class not found, I'm not using it so no big deal but it seems there's probable some more things I need to require once here.

Please Log in to join the conversation.

Moderators: beatnantkrileon
Time to create page: 0.632 seconds

Facebook Twitter LinkedIn