Skip to Content Skip to Menu

Using CB API in another custom module

9 years 11 months ago #254163 by iytworldwide
Using CB API in another custom module was created by iytworldwide
Hi Kyle,

CB: 1.9.1
joomla: 3.3.0

I am writing a component which reads a csv file and does the data upload into Users and CB. I am doing this through the tutorial link given

www.joomlapolis.com/support/tutorials/120-api-usage/18357-including-cb-api-for-usage-outside-of-cb
www.joomlapolis.com/support/tutorials/120-api-usage/18362-registering-a-user-through-cb-api

$user = new moscomprofilerUser( $_CB_database );
$user->usertype = ( $usertype ? $usertype : 'Registered' );
$user->gid = $_CB_framework->acl->get_group_id( $user->usertype, 'ARO' );
$user->gids = array( $user->gid );

I want to know how can I set my custom CB fields through it? As per example following creates an object of Joomla user table and I need to access the user object related to #_comprofiler so that I can set the custom fields (addressline1, addressline2, etc) through object and save it.

I tried to set it in user object with below code but this does not seem to work. It is not giving any error as well. There is proper data in csv for all fields and it is being read correctly as well.
$user->addressline1 = $addressline1;
$user->addressline2 = $addressline2;


I know there is CB juice plugin but I want to to use my version due to multiple business functionality to be integrated in own custom module.

Please guide me how to use comprofiler user object and save data to my custom fields which I have created through CB using API.

Warm Regards,
Amit Dangwal

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 48499
  • Thanks: 8284
  • Karma: 1443
9 years 11 months ago #254177 by krileon
Replied by krileon on topic Using CB API in another custom module
To set field values you just add them to the CB user object. For example if my field is cb_address then I'd just do the following.

$user->set( 'cb_address', 'value here' );

The below will also work, but you should use getters and setters whenever possible.

$user->cb_address = 'value here';

Review CB Auto Actions and its registration.php model found below for detailed usage of registering a user through API.

components/com_comprofiler/plugin/user/plug_cbautoactions/models/registration.php


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 or Create an account to join the conversation.

9 years 11 months ago #254182 by iytworldwide
Replied by iytworldwide on topic Using CB API in another custom module
Thanks Kyle. I will check this.

Please Log in or Create an account to join the conversation.

Moderators: beatnantkrileon
Powered by Kunena Forum