Login

API - Establishing $user PDF Print E-mail
Tutorials - Community Builder
Tuesday, 28 July 2009 08:52
Sometimes $user has yet to be establish in your code; especially if you're using an external code from CB such as a module, but $user is needed for many CB API usages. So you'll need to establish the $user of the logged in user. To do this add the following to your code, which will generate $user as used in CB Plugins.

1
2
3
4
5
6
7
8
9
10
11
12
$myId			=	$_CB_framework->myId();
$cbUser			=&	CBuser::getInstance( $myId );
 
if ( ! $cbUser ) {
	$cbUser		=&	CBuser::getInstance( null );
}
 
$user			=	$cbUser->getUserData();
 
if ( ! $user ) {
	return;
}

Don't forget to add $_CB_framework global if it is yet to be established or it won't function and you'll receive an error. You can remove the $user check if you do not wish your code to stop, but keep note that all $user data will be null so be sure to compensate for this in your code!
Last Updated on Tuesday, 28 July 2009 09:23
 

You are not authorized to comment on this content.