Skip to Content Skip to Menu

🎃 Happy Halloween! Treat yourself with an awesome discount on memberships! Get 20% off now with code SPOOKY-2024!

[SOLVED] Trying to get a CB user object, but that exhausts memory?

  • krileon
  • krileon
  • ONLINE
  • Posts: 48460
  • Thanks: 8280
  • Karma: 1443
8 years 6 months ago #281098 by krileon
User object is already provided so you'd use the following based off your current code.

FROM:
Code:
$cbUser = CBuser::getMyUserDataInstance(); if ( ! $cbUser ) { $cbUser =& CBuser::getInstance( null ); } $user =& $cbUser->getUserData();
TO:
Code:
$user = CBuser::getMyUserDataInstance();

I also don't recommend using direct ->FIELD_NAME, but instead use get/set as needed. Example as follows. Direct usage will still work and continue to work, but we're moving all usages to get/set usages gradually.

FROM:
Code:
$user->name
TO:
Code:
$user->get( 'name' )


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.

  • fribse2011
  • fribse2011
  • OFFLINE
  • Posts: 921
  • Thanks: 79
  • Karma: 8
8 years 6 months ago - 8 years 6 months ago #281114 by fribse2011
I see, ok, good to know, thankyou! I've changed the code to use get, and I'll change the other part to use set.

Is this correct?
Do I still need to do the store at the end?
Code:
$user->set('name') = $form->data['navn1']; $user->set('cb_cell') = $form->data['mobil1']; $user->set('cb_adresse') = $form->data['adresse1']; $user->set('cb_postnummer') = $form->data['post1']; $user->set('cb_birthday') = date_format(date_create_from_format('d/m-Y', $form->data['foedsel1']), 'Y-m-d'); $user->store()

Best regards
Fribse

Frømandsklubben Nikon, www.nikondyk.dk
We're a volunteer driven diving club in Ishøj, Denmark.
Har du brug for en dykkerklub der rummer alle, så kom ned til os.
Last edit: 8 years 6 months ago by fribse2011.

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 48460
  • Thanks: 8280
  • Karma: 1443
8 years 6 months ago - 8 years 6 months ago #281134 by krileon
No, that's not correct. You should have as follows.

Code:
$user->set( 'name', $form->data['navn1'] ); $user->set( 'cb_cell', $form->data['mobil1'] ); $user->set( 'cb_adresse', $form->data['adresse1'] ); $user->set( 'cb_postnummer', $form->data['post1'] ); $user->set( 'cb_birthday', date_format( date_create_from_format( 'd/m-Y', $form->data['foedsel1'] ), 'Y-m-d' ) ); $user->store();

Yes, you still need to do the store.

This assumes you want to add those values to the CB users profile data. Your previous usage on page 1 is the opposite so I've no idea your intentions. set will set a value to the object and get will get a value from the object. Base off page 1 code you'd have the below.

Code:
$form->data['navn1'] = $user->get( 'name' ); $form->data['email1'] = $user->get( 'email' ); $form->data['mobil1'] = $user->get( 'cb_cell' ); $form->data['adresse1'] = $user->get( 'cb_adresse' ); $form->data['post1'] = $user->get( 'cb_postnummer' );


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.
Last edit: 8 years 6 months ago by krileon.
The following user(s) said Thank You: fribse2011

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

  • fribse2011
  • fribse2011
  • OFFLINE
  • Posts: 921
  • Thanks: 79
  • Karma: 8
8 years 6 months ago #281143 by fribse2011
It's a membership form, so first the user registers for the site as a regular joomla user, he can then use the regular functions for our site, I then prepopulate the form with the values already given, and he / she then adds the extra information, or modifies the fields, and then signs up to be a diving club member where he gets full access :-)
Thankyou very much Kyle, your help is invaluable!

Best regards
Fribse

Frømandsklubben Nikon, www.nikondyk.dk
We're a volunteer driven diving club in Ishøj, Denmark.
Har du brug for en dykkerklub der rummer alle, så kom ned til os.
The following user(s) said Thank You: krileon

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

Moderators: beatnantkrileon
Powered by Kunena Forum