Our Tutorials

Sometimes $user has yet to be establish in your code; especially if you're using an external code from Community Builder such as a module, but $user is needed for many Community Builder 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 Community Builder Plugins.
1 2 3 4 |
Global $_CB_framework; $myId = $_CB_framework->myId(); $user =& CBuser::getUserDataInstance( $myId ); |
The above is great for establishing the $user object if this is the very basic you need. However with just the object you can't perform typical CBUser API such as replacement API to allow substitutions on a text string to be parsed. The below will allow usage of CBUser API as well as establish the $user object.
1 2 3 4 5 6 7 8 9 10 |
Global $_CB_framework; $myId = $_CB_framework->myId(); $cbUser =& CBuser::getInstance( $myId ); if ( ! $cbUser ) { $cbUser =& CBuser::getInstance( null ); } $user =& $cbUser->getUserData(); |
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!
| Professional Member |
| |
|
As a Professional member you get all the Advanced privileges (CB detailed documentation, 17+ CB Add-ons, 11 GroupJive) and access to our same or next business day response time support forum for all your websites and our 26+ Incubator add-ons! That's a lot of add-ons that you can use on all your websites for ever!
|