I try to get CB fields outside CB. So I follow the tips found in internet. The code is:
Code:
defined('_JEXEC') or die;
global $_CB_framework, $_PLUGINS, $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' );
}
cbimport( 'cb.html' );
class plgMyPlugin extends JPlugin
{
...
public function onUserAfterLogin($options)
{
....
$theField=$this->myFunction();
}
public function myFunction
{
global $_CB_framework;
$myId = $_CB_framework->myId();
$cbUser =& CBuser::getInstance( $myId );
if ( ! $cbUser )
{
$cbUser =& CBuser::getInstance( null );
}
//$user =& $cbUser->getUserData();
$theField = $cbUser->getField(....);
}
}
I cannot get the expected result. I found the value of $myId is 0.
Will '$_CB_framework->myId();' return right Id in event handler like 'onUserAfterLogin'? or any other cause?