[SOLVED] User Data problem after loading API

12 years 3 months ago - 12 years 3 months ago #190995 by nforse
I've used the snippets provided by Krileon to include the CB API and to establish the $user object. The issue I'm having is I can only retrieve user data for Administrators, not Registered Users.
/* start: set up access to CB API */
	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');
    }
/* end */
    
/* start: establish $user */
    $myId = $_CB_framework->myId();
    $cbUser =& CBuser::getInstance( $myId );
 
    if ( ! $cbUser ) {
        $cbUser =& CBuser::getInstance( null );
    }
 
    $user =& $cbUser->getUserData();
/* end */
    
/* start: set variables for pdf */
    $userFirstName = $user->cb_firstname;
    $userLastName = $user->cb_lastname;

echo $userFirstName;
echo $userLastName;

If I'm logged into my site with a regular, registered user those last two echo lines do not produce the user's first and last name, but if I'm logged in as an administrator they do. Why is this?
The following user(s) said Thank You: mtaras

Please Log in to join the conversation.

12 years 3 months ago #191002 by nforse
Replied by nforse on topic [SOLVED]
The issue was arising from the use of
$user->cb_firstname
vs
$user->firstname
. My code was not presenting a user's first name and last name because I was trying to pull data from different (and empty) fields.

Please Log in to join the conversation.

Moderators: beatnantkrileon
Time to create page: 0.137 seconds

Facebook Twitter LinkedIn