Skip to Content Skip to Menu

use of CB API

  • GUEST
10 years 1 month ago #249381 by
use of CB API was created by
Not sure if this is the right place to post, so please move if not.

2.0RC3 and trying to get the CB User name.
When using the example code from
www.joomlapolis.com/support/tutorials/120-api-usage/18357-including-cb-api-for-usage-outside-of-cb :

global $_CB_framework, $mainframe;

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' );
}

I get:
PHP Fatal error: Call to a member function getCfg() on a non-object, pointing to the line:
if ( ! file_exists( $mainframe->getCfg( 'absolute_path' ) . ....

when running 'php file.php' from shell (on the Joomla/CB server)
From within CB I get a 500 Internal server error

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 48479
  • Thanks: 8283
  • Karma: 1443
10 years 1 month ago #249397 by krileon
Replied by krileon on topic use of CB API
You can't execute CB API outside of Joomla scope. The tutorial is for using CB API outside of CB. For example in a module. When you directly execute a PHP file then Joomla is never prepared and CB needs Joomla API for its own API. If you want to execute CB API as an endpoint you need a Joomla extension or a CB component plugin so you've a URL to navigate to that performs whatever necessary API calls.


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.

  • GUEST
10 years 1 month ago #249407 by
Replied by on topic use of CB API
Thanks for the answer, so how do I debug it. Within Joomla I do an Ajax call to the php file with the above code and get a 500 error.

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 48479
  • Thanks: 8283
  • Karma: 1443
10 years 1 month ago #249408 by krileon
Replied by krileon on topic use of CB API
It needs to path through Joomla. You can't just call that PHP file, that won't work for CB API or Joomla API as Joomla is never initiated. If you're using Ajax then you need an endpoint inside Joomla. Example as follows.

index.php?option=my_component&view=ajax&format=raw

I suggest checking Joomla documentation and tutorials regarding ajax endpoints for further usage information. If you're developing a CB plugin then there's specific functions to be used as ajax response endpoints.


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.

  • GUEST
10 years 1 month ago #249412 by
Replied by on topic use of CB API
Just to be sure I understand you correctly.

I have Joomla and CB installed. I use a Joomla page with a module that enables scripts. On this page is a Java script which uses Ajax to get variables from the Joomla/CBserver. This works since I can receive variables from the server side PHP file. Now I am trying to get the CB username back to the Joomla page by putting the CB API call (above code) in that PHP file.

You're saying the above API example is not the correct way to do this?

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

  • GUEST
10 years 1 month ago #249424 by
Replied by on topic use of CB API
Ok, I think I understand now. The session variables are not available to the PHP file, unless it's
a CB plugin. Since I just need the CB username is there no other quick and dirty way to get this, without going to write a plugin?

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

Moderators: beatnantkrileon
Powered by Kunena Forum