$_CB_framework->myId(); returns 0 always.

11 years 6 days ago #151327 by musicmanaaron82
$_CB_framework->myId(); returns 0 always. was created by musicmanaaron82
Having a big problem not being able to access a member's Id # externally.

I have uninstalled & reinstalled community builder and still having the problem. it first showed up when I uninstalled the facebook connect plugin. The script was working fine before but then started returning nothing but 0 as the id. I do not have CSubs installed and no additional plugins in cb. Only the component and log-in module. I am no expert coder but this worked fine before I uninstalled the plug-in. Something else to mention - before I uninstalled facebook connect I did not need to import cb.plugins and cb.html. But now if I don't I get a Fatal error: Class 'moscomprofilerUser' not found in /home/thewebap/public_html/administrator/components/com_comprofiler/plugin.foundation.php on line 963


I am not saying facebook connect caused it for sure - but it was immediately after.

The script is as follows.
<?php
global $_CB_framework, $mainframe, $_CB_database, $theScore;





define( '_JEXEC', 1 );
define('JPATH_BASE', dirname(__FILE__) );
define( 'DS', DIRECTORY_SEPARATOR );
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
$mainframe =& JFactory::getApplication('site');
jimport('joomla.base.observable');
 
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( 'cb.plugins' );


$myId		=	$_CB_framework->myId();
$cbUser		=&	CBuser::getInstance( $myId );
 
if ( ! $cbUser ) {
	$cbUser	=&	CBuser::getInstance( null );
}
 
$user		=&	$cbUser->getUserData();

$gameField=$_POST['gameField'];
	$lastScore = $cbUser->getField( $gameField, null, 'html', 'none', 'list' );
	
	// $_CB_database->setQuery("UPDATE jos_comprofiler SET cb_instruments = 'Flute' WHERE user_id = $myId");

        $thisScore=$_POST['theScore']; 
       
        if ($thisScore > $lastScore) { 
	
	$_CB_database->setQuery("UPDATE jos_comprofiler SET $gameField = $thisScore WHERE user_id = $myId");
	echo $_CB_database->loadResult();
	writeVariable( "newHigh", "1" );
	}
	else {
	writeVariable( "newHigh", "0" );
	}
$numVariables = 0;

function writeVariable( $name, $value )
{
  if( $numVariables > 0 )
  {
      echo '&';
  }

  echo $name . '=' . urlencode($value);

  $numVariables ++;
}
echo $myId;

php?>

Thank you for your help.

Please Log in to join the conversation.

11 years 6 days ago #151391 by krileon
Replied by krileon on topic Re: $_CB_framework->myId(); returns 0 always.
Based off your code it does not appear you are including CBs API. The reason Facebook Connect allowed your code to work is it includes and establishes the globals on ever page load. Now that it is gone you no longer have that API present. You can certainly use CB API externally however. Please see the below tutorial.

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


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.174 seconds

Facebook Twitter LinkedIn